def add_child_workflow_terminated(self, initiated_id, started_id): initiated_event = self.events[initiated_id - 1] workflow_id = initiated_event.workflow_id workflow_type = initiated_event.workflow_type started_event = self.events[started_id - 1] workflow_execution = started_event.workflow_execution self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "ChildWorkflowExecutionTerminated", "childWorkflowExecutionTerminatedEventAttributes": { "initiatedEventId": initiated_id, "startedEventId": started_id, "workflowExecution": { "runId": workflow_execution["runId"], "workflowId": workflow_id, }, "workflowType": { "name": workflow_type["name"], "version": workflow_type["version"], }, }, })) return self
def add_child_workflow_timed_out(self, initiated_id, started_id, timeout_type): initiated_event = self.events[initiated_id - 1] workflow_id = initiated_event.workflow_id workflow_type = initiated_event.workflow_type started_event = self.events[started_id - 1] workflow_execution = started_event.workflow_execution self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'ChildWorkflowExecutionFailed', 'childWorkflowExecutionFailedEventAttributes': { 'initiatedEventId': initiated_id, 'startedEventId': started_id, 'timeoutType': timeout_type, 'workflowExecution': { 'runId': workflow_execution['runId'], 'workflowId': workflow_id, }, 'workflowType': { 'name': workflow_type['name'], 'version': workflow_type['version'] } } })) return self
def add_decision_task_completed(self, scheduled=None, started=None, execution_context=None): if scheduled is None: scheduled = self.last_id - 1 if started is None: started = self.last_id self.events.append( EventFactory({ "eventId": len(self.events) + 1, "eventType": "DecisionTaskCompleted", "eventTimestamp": new_timestamp_string(), "decisionTaskCompletedEventAttributes": { "startedEventId": started, "scheduledEventId": scheduled, "executionContext": (json.dumps(execution_context) if execution_context is not None else None), } })) return self
def add_activity_task_failed( self, scheduled=None, started=None, reason=DEFAULT_REASON, details=DEFAULT_DETAILS, ): self.events.append( EventFactory({ "eventId": self.next_id, "eventType": "ActivityTaskFailed", "eventTimestamp": new_timestamp_string(), "activityTaskFailedEventAttributes": { "reason": reason, "details": details, "scheduledEventId": (scheduled if scheduled is not None else self.last_id - 1), "startedEventId": (started if started is not None else self.last_id), }, })) return self
def add_child_workflow_started(self, initiated_id, name=None, version=None): initiated_event = self.events[initiated_id - 1] workflow_id = initiated_event.workflow_id workflow_type = initiated_event.workflow_type timestamp = new_timestamp_string() self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': timestamp, 'eventType': 'ChildWorkflowExecutionStarted', 'childWorkflowExecutionStartedEventAttributes': { 'initiatedEventId': initiated_id, 'workflowExecution': { 'runId': timestamp, 'workflowId': workflow_id, }, 'workflowType': { 'name': workflow_type['name'], 'version': workflow_type['version'], } } })) return self
def add_child_workflow_start_initiated(self, workflow, workflow_id=None, task_list=None, input=None, control=None, tag_list=None, task_start_to_close_timeout=0): if control is None: control = {} self.events.append(EventFactory({ 'eventId': self.next_id, 'eventType': 'StartChildWorkflowExecutionInitiated', 'eventTimestamp': new_timestamp_string(), 'startChildWorkflowExecutionInitiatedEventAttributes': { 'control': (json.dumps(control) if control is not None else None), 'childPolicy': 'TERMINATE', 'decisionTaskCompletedEventId': 76, 'executionStartToCloseTimeout': '432000', 'input': (json.dumps(input) if input is not None else '{}'), 'tagList': tag_list, 'taskList': task_list, 'taskStartToCloseTimeout': task_start_to_close_timeout, 'workflowId': workflow_id, 'workflowType': { 'name': workflow.name, 'version': workflow.version } } })) return self
def add_child_workflow_completed(self, initiated_id, started_id, result=None): initiated_event = self.events[initiated_id - 1] workflow_id = initiated_event.workflow_id workflow_type = initiated_event.workflow_type started_event = self.events[started_id - 1] workflow_execution = started_event.workflow_execution self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'ChildWorkflowExecutionCompleted', 'childWorkflowExecutionCompletedEventAttributes': { 'initiatedEventId': initiated_id, 'result': result, 'startedEventId': started_id, 'workflowExecution': { 'runId': workflow_execution['runId'], 'workflowId': workflow_id }, 'workflowType': { 'name': workflow_type['name'], 'version': workflow_type['version'] } }, })) return self
def add_activity_task_scheduled(self, activity, decision_id, activity_id=None, input=None, control=None): if control is None: control = {} self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "ActivityTaskScheduled", "eventTimestamp": new_timestamp_string(), "activityTaskScheduledEventAttributes": { 'control': (json.dumps(control) if control is not None else None), "taskList": { "name": activity.task_list, }, "scheduleToCloseTimeout": activity.task_schedule_to_close_timeout, "activityType": { "name": activity.name, "version": activity.version, }, "heartbeatTimeout": activity.task_heartbeat_timeout, "activityId": (activity_id if activity_id is not None else '{}-{}'.format( activity.name, hash(activity.name))), "scheduleToStartTimeout": activity.task_schedule_to_start_timeout, "decisionTaskCompletedEventId": decision_id, "input": json.dumps(input if input is not None else {}), "startToCloseTimeout": activity.task_start_to_close_timeout, } })) return self
def add_timer_canceled(self, timer_id, started_timer_id=0): self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "TimerCanceled", "timerCanceledEventAttributes": { "timerId": timer_id, "startedEventId": started_timer_id, }, })) return self
def add_activity_task_started(self, scheduled): self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "ActivityTaskStarted", "eventTimestamp": new_timestamp_string(), "activityTaskStartedEventAttributes": { "scheduledEventId": scheduled, "identity": DEFAULT_WORKER_IDENTITY, } })) return self
def add_timer_canceled(self, timer_id, started_timer_id=0): self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'TimerCanceled', 'timerCanceledEventAttributes': { 'timerId': timer_id, 'startedEventId': started_timer_id, } })) return self
def add_request_cancel(self, cause=None, external_event_id=0): self.events.append(EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'WorkflowExecutionCancelRequested', 'workflowExecutionCancelRequestedEventAttributes': { 'externalInitiatedEventId': external_event_id, 'cause': cause } })) return self
def add_signal(self, name, input=None, external_event_id=0): self.events.append(EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'WorkflowExecutionSignaled', 'workflowExecutionSignaledEventAttributes': { 'externalInitiatedEventId': external_event_id, 'input': json.dumps(input) if input is not None else '{}', 'signalName': name, } })) return self
def add_request_cancel(self, cause=None, external_event_id=0): self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "WorkflowExecutionCancelRequested", "workflowExecutionCancelRequestedEventAttributes": { "externalInitiatedEventId": external_event_id, "cause": cause, }, })) return self
def add_marker(self, name, details=None): self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "MarkerRecorded", "markerRecordedEventAttributes": { "details": json_dumps(details) if details is not None else "{}", "markerName": name, }, })) return self
def add_signal(self, name, input=None, external_event_id=0): self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "WorkflowExecutionSignaled", "workflowExecutionSignaledEventAttributes": { "externalInitiatedEventId": external_event_id, "input": json_dumps(input) if input is not None else "{}", "signalName": name, }, })) return self
def add_activity_task_completed(self, scheduled, started, result=None): self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "ActivityTaskCompleted", "eventTimestamp": new_timestamp_string(), "activityTaskCompletedEventAttributes": { "startedEventId": started, "scheduledEventId": scheduled, "result": json.dumps(result) if result is not None else None, } })) return self
def add_marker(self, name, details=None): self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'MarkerRecorded', 'markerRecordedEventAttributes': { 'details': json_dumps(details) if details is not None else '{}', 'markerName': name, } })) return self
def add_decision_task_started(self, scheduled=None): if scheduled is None: scheduled = self.last_id self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "DecisionTaskStarted", "eventTimestamp": new_timestamp_string(), "decisionTaskStartedEventAttributes": { "scheduledEventId": scheduled, "identity": DEFAULT_DECIDER_IDENTITY, } })) return self
def add_decision_task_scheduled(self): self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "DecisionTaskScheduled", "eventTimestamp": new_timestamp_string(), "decisionTaskScheduledEventAttributes": { "startToCloseTimeout": self._workflow.decision_tasks_timeout, "taskList": { "name": self._workflow.task_list, } } })) return self
def add_activity_task_schedule_failed(self, activity_id, decision_id, activity_type, cause): self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": 1386947268.527, "eventType": "ScheduleActivityTaskFailed", "scheduleActivityTaskFailedEventAttributes": { "activityId": activity_id, "activityType": activity_type.copy(), "cause": cause, "decisionTaskCompletedEventId": decision_id, } })) return self
def add_activity_task_schedule_failed(self, activity_id, decision_id, activity_type, cause): self.events.append( EventFactory({ u'eventId': self.next_id, u'eventTimestamp': 1386947268.527, u'eventType': u'ScheduleActivityTaskFailed', u'scheduleActivityTaskFailedEventAttributes': { u'activityId': activity_id, u'activityType': activity_type.copy(), u'cause': cause, u'decisionTaskCompletedEventId': decision_id, } })) return self
def add_activity_task_failed(self, scheduled=None, started=None, reason=DEFAULT_REASON, details=DEFAULT_DETAILS): self.events.append(EventFactory({ 'eventId': self.next_id, 'eventType': 'ActivityTaskFailed', 'eventTimestamp': new_timestamp_string(), 'activityTaskFailedEventAttributes': { 'reason': reason, 'details': details, 'scheduledEventId': (scheduled if scheduled is not None else self.last_id - 1), 'startedEventId': (started if started is not None else self.last_id) } })) return self
def add_activity_task_timed_out(self, timeout_type, scheduled=None, started=None): if scheduled is None: scheduled = self.last_id - 1 if started is None: started = self.last_id self.events.append(EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'ActivityTaskTimedOut', 'activityTaskTimedOutEventAttributes': { 'scheduledEventId': scheduled, 'startedEventId': started, 'timeoutType': timeout_type, } }))
def add_timer_started(self, timer_id, timeout, control=None, decision_id=0): d = { "decisionTaskCompletedEventId": decision_id, 'startToFireTimeout': str(timeout), 'timerId': timer_id, } if control is not None: d['control'] = json_dumps(control) self.events.append( EventFactory({ 'eventId': self.next_id, 'eventTimestamp': new_timestamp_string(), 'eventType': 'TimerStarted', 'timerStartedEventAttributes': d })) return self
def add_timer_started(self, timer_id, timeout, control=None, decision_id=0): d = { "decisionTaskCompletedEventId": decision_id, "startToFireTimeout": str(timeout), "timerId": timer_id, } if control is not None: d["control"] = json_dumps(control) self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "TimerStarted", "timerStartedEventAttributes": d, })) return self
def add_activity_task_timed_out(self, timeout_type, scheduled=None, started=None): if scheduled is None: scheduled = self.last_id - 1 if started is None: started = self.last_id self.events.append( EventFactory({ "eventId": self.next_id, "eventTimestamp": new_timestamp_string(), "eventType": "ActivityTaskTimedOut", "activityTaskTimedOutEventAttributes": { "scheduledEventId": scheduled, "startedEventId": started, "timeoutType": timeout_type, }, }))
def add_decision_task_timed_out(self, scheduled=None, started=None, timeout_type='START_TO_CLOSE'): if scheduled is None: scheduled = self.last_id - 1 if started is None: started = self.last_id self.events.append(EventFactory({ "eventId": len(self.events) + 1, "eventType": "DecisionTaskTimedOut", "eventTimestamp": new_timestamp_string(), "decisionTaskTimedOutEventAttributes": { "startedEventId": started, "scheduledEventId": scheduled, "timeoutType": timeout_type, } })) return self
def __init__(self, workflow, input=None, tag_list=None): """ Bootstrap a history with the first events added by SWF. :param workflow: workflow to simulate :type workflow: declarative.Workflow :param input: JSON serializable dict :type input: dict :param tag_list: string of tags (beware not a list) :type tag_list: str """ self._workflow = workflow self.events = [ EventFactory({ "eventId": 1, "eventType": "WorkflowExecutionStarted", "eventTimestamp": new_timestamp_string(), "workflowExecutionStartedEventAttributes": { "taskList": { "name": workflow.task_list, }, "parentInitiatedEventId": 0, "taskStartToCloseTimeout": workflow.decision_tasks_timeout, "childPolicy": "TERMINATE", "executionStartToCloseTimeout": workflow.execution_timeout, "input": json.dumps(input if input else {}), "workflowType": { "name": workflow.name, "version": workflow.version }, "tagList": tag_list or getattr(workflow, 'tag_list', None) } }) ] self.add_decision_task_scheduled() self.add_decision_task_started(len(self.events))
def add_child_workflow_start_initiated( self, workflow, workflow_id=None, task_list=None, input=None, control=None, tag_list=None, task_start_to_close_timeout=0, ): if control is None: control = {} self.events.append( EventFactory({ "eventId": self.next_id, "eventType": "StartChildWorkflowExecutionInitiated", "eventTimestamp": new_timestamp_string(), "startChildWorkflowExecutionInitiatedEventAttributes": { "control": json_dumps(control), "childPolicy": "TERMINATE", "decisionTaskCompletedEventId": 76, "executionStartToCloseTimeout": "432000", "input": json_dumps(input) if input is not None else "{}", "tagList": tag_list, "taskList": { "name": task_list }, "taskStartToCloseTimeout": task_start_to_close_timeout, "workflowId": workflow_id, "workflowType": { "name": workflow.name, "version": workflow.version, }, }, })) return self