def handle_python(self, _task: OrcaTask): log.debug(" exec python file : " + _task.python) resolved_file = self._resolve_file_path(_task.python, ".py") config = _task.config try: if resolved_file is None: exec(_task.python, _task.locals) else: with open(resolved_file, 'r') as script: _python = script.read() exec(_python, _task.locals) if 'callable' in config: call_str = self.__get_call_string(config, _python) exec(call_str, _task.locals) _task.status = "success" except IndexError: raise ExecutionError( 'The function {0} was not defined in the file: {1}'.format(_task.config.get('callable'), _task.python) ) except BaseException as e: _task.status = "failed" log.debug(str(e)) raise # remove after execution keys_to_remove = [k for k in _task.locals if k not in _task.outputs and k not in _task.inputs] for key in keys_to_remove: del _task.locals[key]
def _handle_task(self, task_dict: Dict) -> OrcaTask: name = task_dict.get('task', None) # check the symbol table for task name to be an unique and valid name self._check_symtable(name, task_dict) # task_locals are the resolved inputs, they will be used for # execution task_locals = self.resolve_task_inputs(task_dict) _task = OrcaTask(task_dict, task_locals) log.debug("task '{0}' locals pre: {1}".format(_task.name, _task.locals)) # select the handler and call handle handle = self.select_handler(task_dict) log.info('Starting task {0}'.format(name)) handle(_task) log.info('Task {0} completed'.format(name, )) log.debug("task '{0}' locals post: {1}".format( _task.name, _task.locals)) # put the task_locals into the global task dictonary # this includes input and outputs task[_task.name] = {} for k, v in _task.locals.items(): task[_task.name][k] = v return _task
def test_file_inputs_python(self): mock = tasks.file_python_inputs_mock h = ExecutionHandler() _task = OrcaTask(mock, h.resolve_task_inputs(mock)) h.handle_python(_task) assert 'result' in _task.locals assert _task.locals['result'] == 25
def test_inline_python(self): mock = tasks.inline_python_mock h = ExecutionHandler() _task = OrcaTask(mock, h.resolve_task_inputs(mock)) h.handle_python(_task) assert 'greeting' in _task.locals assert _task.locals['greeting'] == 'Hello World'
def _handle_task(self, task_dict: Dict): def select_handler(self, task_dict: Dict): if 'csip' in task_dict: return self.handle_csip elif 'http' in task_dict: return self.handle_http elif 'bash' in task_dict: return self.handle_bash elif 'python' in task_dict: return self.handle_python else: raise ConfigurationError( 'Invalid task type: "{0}"'.format(task_dict)) handle = select_handler(self, task_dict) _task = OrcaTask(task_dict, {}) handle(_task)
def test_bad_file_python(self): mock = tasks.bad_file_path_python h = ValidationHandler() _task = OrcaTask(mock, h.resolve_task_inputs(mock)) with self.assertRaises(ConfigurationError): h.handle_python(_task)