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_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