def schedule_lambda_invocation(self, invocation_id, function_name, input_arg, timeout=None): """ Add a ScheduleLambdaFunction decision to the list of decisions. :param invocation_id: The id to use for the event :param function_name: Lambda function name :param input_arg: Input argument to the lambda function. It should be a JSON-serializable object. :param timeout: Timeout value, in seconds, after which the lambda function is considered to have failed if it has not returned. """ attributes = {'id': invocation_id, 'name': function_name} if input_arg is not None: attributes['input'] = utils.encode_task_input(input_arg) if timeout: attributes['startToCloseTimeout'] = str(timeout) self.decisions.append({ 'decisionType': 'ScheduleLambdaFunction', 'scheduleLambdaFunctionDecisionAttributes': attributes })
def set_marker(self, invocation_id, value): self.decisions.append({ 'decisionType': 'RecordMarker', 'recordMarkerDecisionAttributes': { 'markerName': invocation_id, 'details': utils.encode_task_input(value) } })
def complete_workflow(self, result): """ Schedule a CompleteWorkflow decision to indicate the workflow successfully completed :param result: The value to set as the result of the workflow """ self.workflow_state.completed = True self.decisions.append({ 'decisionType': 'CompleteWorkflowExecution', 'completeWorkflowExecutionDecisionAttributes': { 'result': utils.encode_task_input(result) } })
def schedule_child_workflow_invocation( self, invocation_id, name, version, input_arg=None, child_policy=None, lambda_role=None, task_list=None, execution_start_to_close_timeout=None): attributes = { 'workflowId': invocation_id, 'workflowType': { 'name': name, 'version': version } } if input_arg is not None: attributes['input'] = utils.encode_task_input(input_arg) if child_policy is not None: attributes['childPolicy'] = child_policy if lambda_role is None: lambda_role = self.workflow_state.lambda_role if lambda_role is not None: attributes['lambdaRole'] = lambda_role if task_list is not None: attributes['taskList'] = {'name': task_list} if execution_start_to_close_timeout is not None: attributes['executionStartToCloseTimeout'] = str( execution_start_to_close_timeout) self.decisions.append({ 'decisionType': 'StartChildWorkflowExecution', 'startChildWorkflowExecutionDecisionAttributes': attributes })
def schedule_activity_invocation(self, invocation_id, activity_name, activity_version, input_arg, timeout=None, task_list=None): """ Add a ScheduleActivityTask decision to the list of decisions. :param invocation_id: The id to use for the event :param activity_name: Activity type name :param activity_version: Activity type version :param input_arg: Input argument to the activity. It should be a JSON-serializable object. :param timeout: Timeout value, in seconds, after which the activity task is considered to have failed if it has not returned. :param task_list: Name of the SWF task list that the activity worker is listening for events on. If not given, The default registered with the activity type will be used. """ attributes = { 'activityId': invocation_id, 'activityType': { 'name': activity_name, 'version': activity_version } } if input_arg is not None: attributes['input'] = utils.encode_task_input(input_arg) if timeout: attributes['startToCloseTimeout'] = str(timeout) if task_list: attributes['taskList'] = {'name': task_list} self.decisions.append({ 'decisionType': 'ScheduleActivityTask', 'scheduleActivityTaskDecisionAttributes': attributes })
def schedule_signal(self, invocation_id, workflow_id, input_arg=None, run_id=None, control=None): attributes = {'signalName': invocation_id, 'workflowId': workflow_id} if input_arg is not None: attributes['input'] = utils.encode_task_input(input_arg) if run_id is not None: attributes['runId'] = run_id if control is not None: attributes['control'] = control self.decisions.append({ 'decisionType': 'SignalExternalWorkflowExecution', 'signalExternalWorkflowExecutionDecisionAttributes': attributes })