def create_request_cancel_activity_task_decision(self): try_cancel = RequestCancelActivityTaskDecisionAttributes() try_cancel.activity_id = self.schedule_attributes.activity_id decision = Decision() decision.request_cancel_activity_task_decision_attributes = try_cancel decision.decision_type = DecisionType.RequestCancelActivityTask return decision
def cancel_workflow_execution(self): logger.info("Canceling workflow: %s", self.execution_id) decision = Decision() attr = CancelWorkflowExecutionDecisionAttributes() attr.details = None decision.cancel_workflow_execution_decision_attributes = attr decision.decision_type = DecisionType.CancelWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def complete_workflow_execution(self, ret_value): # PORT: addAllMissingVersionMarker(false, Optional.empty()); decision = Decision() attr = CompleteWorkflowExecutionDecisionAttributes() attr.result = json.dumps(ret_value) decision.complete_workflow_execution_decision_attributes = attr decision.decision_type = DecisionType.CompleteWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def fail_workflow_execution(self, exception): # PORT: addAllMissingVersionMarker(false, Optional.empty()); decision = Decision() fail_attributes = FailWorkflowExecutionDecisionAttributes() fail_attributes.reason = "WorkflowFailureException" fail_attributes.details = serialize_exception(exception) decision.fail_workflow_execution_decision_attributes = fail_attributes decision.decision_type = DecisionType.FailWorkflowExecution decision_id = DecisionId(DecisionTarget.SELF, 0) self.add_decision(decision_id, CompleteWorkflowStateMachine(decision_id, decision)) self.completed = True
def record_marker(self, marker_name: str, header: Header, details: bytes): marker = RecordMarkerDecisionAttributes() marker.marker_name = marker_name marker.header = header marker.details = details decision = Decision() decision.decision_type = DecisionType.RecordMarker decision.record_marker_decision_attributes = marker next_decision_event_id = self.decider.next_decision_event_id decision_id = DecisionId(DecisionTarget.MARKER, next_decision_event_id) self.decider.add_decision(decision_id, MarkerDecisionStateMachine(id=decision_id, decision=decision))
def create_cancel_timer_decision(self): try_cancel = CancelTimerDecisionAttributes() try_cancel.timer_id = self.start_timer_attributes.timer_id decision: Decision = Decision() decision.cancel_timer_decision_attributes = try_cancel decision.decision_type = DecisionType.CancelTimer return decision
def test_get_decisions(self): decision = Decision() state_machine: DecisionStateMachine = Mock() state_machine.get_decision = MagicMock(return_value=decision) self.decider.decisions[DecisionId(DecisionTarget.ACTIVITY, 10)] = state_machine decisions = self.decider.get_decisions() self.assertEqual(1, len(decisions)) self.assertIs(decision, decisions[0])
def create_start_timer_decision(self): decision: Decision = Decision() decision.start_timer_decision_attributes = self.start_timer_attributes decision.decision_type = DecisionType.StartTimer return decision
def create_schedule_activity_task_decision(self): decision = Decision() decision.schedule_activity_task_decision_attributes = self.schedule_attributes decision.decision_type = DecisionType.ScheduleActivityTask return decision
def setUp(self) -> None: self.decision_id = DecisionId(DecisionTarget.SELF, 256) self.decision = Decision() self.state_machine = CompleteWorkflowStateMachine( self.decision_id, self.decision)