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
def __init__(self, name, status, result=None, context=None): if not statuses.is_valid(status): raise exc.InvalidStatus(status) self.name = name self.status = status self.result = result self.context = context
def is_transition_valid(cls, old_status, new_status): if old_status is None: old_status = 'null' if new_status is None: new_status = 'null' if not statuses.is_valid(old_status): raise exc.InvalidStatus(old_status) if not statuses.is_valid(new_status): raise exc.InvalidStatus(new_status) if old_status not in TASK_STATE_MACHINE_DATA.keys(): return False if old_status == new_status or new_status in TASK_STATE_MACHINE_DATA[old_status].values(): return True return False