def request_workflow_status(self, status): # Record current workflow status. current_status = self.get_workflow_status() # Create an event for the request. wf_ex_event = events.WorkflowExecutionEvent(status) # Push the event to all the active tasks. The event may trigger status changes to the task. for task_state in self.workflow_state.get_tasks_by_status(statuses.ACTIVE_STATUSES): machines.TaskStateMachine.process_event(self.workflow_state, task_state, wf_ex_event) # Process the workflow status change event. machines.WorkflowStateMachine.process_event(self.workflow_state, wf_ex_event) # Get workflow status after event is processed. updated_status = self.get_workflow_status() # Ignore if workflow hasn't changed from paused to pausing. if (status == statuses.PAUSED and current_status == statuses.PAUSING and updated_status == statuses.PAUSING): return # Ignore if workflow hasn't changed from canceled to canceling. if (status == statuses.CANCELED and current_status == statuses.CANCELING and updated_status == statuses.CANCELING): return # Otherwise, if status has not changed as expected, then raise exception. if status != current_status and current_status == updated_status: raise exc.InvalidWorkflowStatusTransition(current_status, wf_ex_event.name)
def request_workflow_state(self, state): # Record current workflow state. current_state = self.get_workflow_state() # Create an event for the request. wf_ex_event = events.WorkflowExecutionEvent(state) # Push the event to all the active tasks. The event may trigger state changes to the task. for task in self.flow.get_tasks_by_state(states.ACTIVE_STATES): machines.TaskStateMachine.process_event(self, task, wf_ex_event) # Process the workflow state change event. machines.WorkflowStateMachine.process_event(self, wf_ex_event) # Get workflow state after event is processed. updated_state = self.get_workflow_state() # If state has not changed as expected, then raise exception. if state != current_state and current_state == updated_state: raise exc.InvalidWorkflowStateTransition(current_state, wf_ex_event.name)