def after_task_complete(self, task_ex, task_spec): super(WaitAfterPolicy, self).after_task_complete(task_ex, task_spec) context_key = 'wait_after_policy' runtime_context = _ensure_context_has_key( task_ex.runtime_context, context_key ) task_ex.runtime_context = runtime_context policy_context = runtime_context[context_key] if policy_context.get('skip'): # Skip, already processed. return policy_context.update({'skip': True}) _log_task_delay(task_ex, self.delay) state = task_ex.state # Set task state to 'DELAYED'. task_ex.state = states.DELAYED # Schedule to change task state to RUNNING again. scheduler.schedule_call( _ENGINE_CLIENT_PATH, 'on_task_state_change', self.delay, state=state, task_ex_id=task_ex.id, )
def _schedule_run_workflow(task_ex, task_spec, wf_input, index): parent_wf_ex = task_ex.workflow_execution parent_wf_spec = spec_parser.get_workflow_spec(parent_wf_ex.spec) wf_spec_name = task_spec.get_workflow_name() wf_def = e_utils.resolve_workflow_definition(parent_wf_ex.workflow_name, parent_wf_spec.get_name(), wf_spec_name) wf_spec = spec_parser.get_workflow_spec(wf_def.spec) wf_params = {'task_execution_id': task_ex.id, 'with_items_index': index} if 'env' in parent_wf_ex.params: wf_params['env'] = parent_wf_ex.params['env'] for k, v in wf_input.items(): if k not in wf_spec.get_input(): wf_params[k] = v del wf_input[k] scheduler.schedule_call(None, 'mistral.engine.task_handler.run_workflow', 0, wf_name=wf_def.name, wf_input=wf_input, wf_params=wf_params)
def _schedule_run_action(task_ex, task_spec, action_input, index): wf_ex = task_ex.workflow_execution wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) action_spec_name = task_spec.get_action_name() # TODO(rakhmerov): Refactor ad-hoc actions and isolate them. action_def = e_utils.resolve_action_definition(wf_ex.workflow_name, wf_spec.get_name(), action_spec_name) if action_def.spec: # Ad-hoc action. action_spec = spec_parser.get_action_spec(action_def.spec) base_name = action_spec.get_base() action_def = e_utils.resolve_action_definition(task_ex.workflow_name, wf_spec.get_name(), base_name) action_ex = _create_action_execution(task_ex, action_def, action_input, index) target = expr.evaluate_recursively( task_spec.get_target(), utils.merge_dicts(copy.deepcopy(action_input), copy.copy(task_ex.in_context))) scheduler.schedule_call(None, 'mistral.engine.task_handler.run_action', 0, action_ex_id=action_ex.id, target=target)
def after_task_complete(self, task_ex, task_spec): super(WaitAfterPolicy, self).after_task_complete(task_ex, task_spec) context_key = 'wait_after_policy' runtime_context = _ensure_context_has_key(task_ex.runtime_context, context_key) task_ex.runtime_context = runtime_context policy_context = runtime_context[context_key] if policy_context.get('skip'): # Skip, already processed. return policy_context.update({'skip': True}) _log_task_delay(task_ex, self.delay) state = task_ex.state # Set task state to 'DELAYED'. task_ex.state = states.DELAYED # Schedule to change task state to RUNNING again. scheduler.schedule_call( _ENGINE_CLIENT_PATH, 'on_task_state_change', self.delay, state=state, task_ex_id=task_ex.id, )
def before_task_start(self, task_ex, task_spec): super(WaitBeforePolicy, self).before_task_start(task_ex, task_spec) context_key = 'wait_before_policy' runtime_context = _ensure_context_has_key(task_ex.runtime_context, context_key) task_ex.runtime_context = runtime_context policy_context = runtime_context[context_key] if policy_context.get('skip'): # Unset state 'DELAYED'. wf_trace.info( task_ex, "Task '%s' [%s -> %s]" % (task_ex.name, states.DELAYED, states.RUNNING)) task_ex.state = states.RUNNING return policy_context.update({'skip': True}) _log_task_delay(task_ex, self.delay) task_ex.state = states.DELAYED scheduler.schedule_call( None, _RUN_EXISTING_TASK_PATH, self.delay, task_ex_id=task_ex.id, )
def after_task_complete(self, task_ex, task_spec): """Possible Cases: 1. state = SUCCESS No need to move to next iteration. 2. retry:count = 5, current:count = 2, state = ERROR, state = IDLE/DELAYED, current:count = 3 3. retry:count = 5, current:count = 4, state = ERROR Iterations complete therefore state = #{state}, current:count = 4. """ super(RetryPolicy, self).after_task_complete(task_ex, task_spec) context_key = 'retry_task_policy' runtime_context = _ensure_context_has_key( task_ex.runtime_context, context_key ) task_ex.runtime_context = runtime_context state = task_ex.state if state != states.ERROR: return wf_trace.info( task_ex, "Task '%s' [%s -> ERROR]" % (task_ex.name, task_ex.state) ) policy_context = runtime_context[context_key] retry_no = 0 if 'retry_no' in policy_context: retry_no = policy_context['retry_no'] del policy_context['retry_no'] retries_remain = retry_no + 1 < self.count if not retries_remain or self.break_on: return _log_task_delay(task_ex, self.delay) task_ex.state = states.DELAYED policy_context['retry_no'] = retry_no + 1 runtime_context[context_key] = policy_context scheduler.schedule_call( None, _RUN_EXISTING_TASK_PATH, self.delay, task_ex_id=task_ex.id, )
def after_task_complete(self, task_ex, task_spec): """Possible Cases: 1. state = SUCCESS No need to move to next iteration. 2. retry:count = 5, current:count = 2, state = ERROR, state = IDLE/DELAYED, current:count = 3 3. retry:count = 5, current:count = 4, state = ERROR Iterations complete therefore state = #{state}, current:count = 4. """ super(RetryPolicy, self).after_task_complete(task_ex, task_spec) context_key = 'retry_task_policy' runtime_context = _ensure_context_has_key(task_ex.runtime_context, context_key) task_ex.runtime_context = runtime_context state = task_ex.state if state != states.ERROR: return wf_trace.info( task_ex, "Task '%s' [%s -> ERROR]" % (task_ex.name, task_ex.state)) policy_context = runtime_context[context_key] retry_no = 0 if 'retry_no' in policy_context: retry_no = policy_context['retry_no'] del policy_context['retry_no'] retries_remain = retry_no + 1 < self.count if not retries_remain or self.break_on: return _log_task_delay(task_ex, self.delay) task_ex.state = states.DELAYED policy_context['retry_no'] = retry_no + 1 runtime_context[context_key] = policy_context scheduler.schedule_call( None, _RUN_EXISTING_TASK_PATH, self.delay, task_ex_id=task_ex.id, )
def before_task_start(self, task_ex, task_spec): super(TimeoutPolicy, self).before_task_start(task_ex, task_spec) scheduler.schedule_call( None, 'mistral.engine.policies.fail_task_if_incomplete', self.delay, task_ex_id=task_ex.id, timeout=self.delay) wf_trace.info( task_ex, "Timeout check scheduled [task=%s, timeout(s)=%s]." % (task_ex.id, self.delay))
def before_task_start(self, task_ex, task_spec): super(TimeoutPolicy, self).before_task_start(task_ex, task_spec) scheduler.schedule_call( None, 'mistral.engine.policies.fail_task_if_incomplete', self.delay, task_ex_id=task_ex.id, timeout=self.delay ) wf_trace.info( task_ex, "Timeout check scheduled [task=%s, timeout(s)=%s]." % (task_ex.id, self.delay) )
def _schedule_noop_action(task_ex, task_spec): wf_ex = task_ex.workflow_execution wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) action_def = e_utils.resolve_action_definition(wf_ex.workflow_name, wf_spec.get_name(), 'std.noop') action_ex = _create_action_execution(task_ex, action_def, {}) target = expr.evaluate_recursively(task_spec.get_target(), task_ex.in_context) scheduler.schedule_call(None, 'mistral.engine.task_handler.run_action', 0, action_ex_id=action_ex.id, target=target)
def before_task_start(self, task_ex, task_spec): super(WaitBeforePolicy, self).before_task_start(task_ex, task_spec) context_key = 'wait_before_policy' runtime_context = _ensure_context_has_key( task_ex.runtime_context, context_key ) task_ex.runtime_context = runtime_context policy_context = runtime_context[context_key] if policy_context.get('skip'): # Unset state 'DELAYED'. wf_trace.info( task_ex, "Task '%s' [%s -> %s]" % (task_ex.name, states.DELAYED, states.RUNNING) ) task_ex.state = states.RUNNING return policy_context.update({'skip': True}) _log_task_delay(task_ex, self.delay) task_ex.state = states.DELAYED scheduler.schedule_call( None, _RUN_EXISTING_TASK_PATH, self.delay, task_ex_id=task_ex.id, )