def process_workflow_event(cls, workflow_state, task_state, wf_ex_event): # Check if event is valid. if wf_ex_event.name not in events.WORKFLOW_EXECUTION_EVENTS: raise exc.InvalidEvent(wf_ex_event.name) # Append additional task context to the event. event_name = cls.add_context_to_workflow_event(workflow_state, task_state['id'], task_state['route'], wf_ex_event) # Identify current task status. current_task_status = task_state.get('status', statuses.UNSET) if current_task_status is None: current_task_status = statuses.UNSET if current_task_status not in statuses.ALL_STATUSES: raise exc.InvalidStatus(current_task_status) if current_task_status not in TASK_STATE_MACHINE_DATA: raise exc.InvalidTaskStatusTransition(current_task_status, event_name) # If no transition is identified, then there is no status change. if event_name not in TASK_STATE_MACHINE_DATA[current_task_status]: return new_task_status = TASK_STATE_MACHINE_DATA[current_task_status][ event_name] # Assign new status to the task flow entry. task_state['status'] = new_task_status
def process_workflow_event(cls, workflow_state, wf_ex_event): # Append additional workflow context to the event. event_name = cls.add_context_to_workflow_event(workflow_state, wf_ex_event) # Check if event is valid. if event_name not in events.WORKFLOW_EXECUTION_EVENTS: raise exc.InvalidEvent(event_name) # Capture current workflow status. current_workflow_status = workflow_state.status new_workflow_status = current_workflow_status # Check if the current workflow status can be transitioned. if current_workflow_status not in WORKFLOW_STATE_MACHINE_DATA: raise exc.InvalidWorkflowStatusTransition(current_workflow_status, event_name) # If the current workflow status can be transitioned and there is no match on the # event, then there is not status transition. if event_name not in WORKFLOW_STATE_MACHINE_DATA[ current_workflow_status]: return new_workflow_status = WORKFLOW_STATE_MACHINE_DATA[ current_workflow_status][event_name] # Assign new workflow status if there is change. if current_workflow_status != new_workflow_status: workflow_state.status = new_workflow_status
def process_task_item_event(cls, workflow_state, task_state, ac_ex_event): # Check if event is valid. if ac_ex_event.name not in events.ACTION_EXECUTION_EVENTS + events.ENGINE_OPERATION_EVENTS: raise exc.InvalidEvent(ac_ex_event.name) # Append additional task context to the event. event_name = cls.add_context_to_task_item_event( workflow_state, task_state["id"], task_state["route"], ac_ex_event) # Identify current task status. current_task_status = task_state.get("status", statuses.UNSET) if current_task_status is None: current_task_status = statuses.UNSET if current_task_status not in statuses.ALL_STATUSES: raise exc.InvalidStatus(current_task_status) if current_task_status not in TASK_STATE_MACHINE_DATA: raise exc.InvalidTaskStatusTransition(current_task_status, event_name) # If no transition is identified, then there is no status change. if event_name not in TASK_STATE_MACHINE_DATA[current_task_status]: return new_task_status = TASK_STATE_MACHINE_DATA[current_task_status][ event_name] # Assign new status to the task flow entry. task_state["status"] = new_task_status
def process_task_event(cls, workflow_state, tk_ex_event): # Append additional workflow context to the event. event_name = cls.add_context_to_task_event(workflow_state, tk_ex_event) # Check if event is valid. if event_name not in events.TASK_EXECUTION_EVENTS: raise exc.InvalidEvent(event_name) # Capture current workflow status. current_workflow_status = workflow_state.status new_workflow_status = current_workflow_status # Check if the current workflow status can be transitioned. if current_workflow_status not in WORKFLOW_STATE_MACHINE_DATA: raise exc.InvalidWorkflowStatusTransition(current_workflow_status, event_name) # If the current workflow status can be transitioned and there is no match on the # event, then there is not status transition. if event_name not in WORKFLOW_STATE_MACHINE_DATA[ current_workflow_status]: return new_workflow_status = WORKFLOW_STATE_MACHINE_DATA[ current_workflow_status][event_name] # Assign new workflow status if there is change. if current_workflow_status != new_workflow_status: workflow_state.status = new_workflow_status # If the final workflow status here is completed, then ensure there is no unreachable # barrier task(s). A barrier task is unreachable if the workflow is completed but then one # or more criteria for the task is satisified. In this case, log the task and fail the # workflow to notify that the execution is incomplete but unable to proceed. if workflow_state.status in statuses.COMPLETED_STATUSES: unreachable_barriers = workflow_state.get_unreachable_barriers() # If there are unreachable barrier tasks, then change workflow status to failed # and write an error log for each case. if unreachable_barriers: workflow_state.status = statuses.FAILED for entry in unreachable_barriers: e = exc.UnreachableJoinError(entry["id"], entry["route"]) workflow_state.conductor.log_error(e, task_id=entry["id"], route=entry["route"])