def test_list_invalid_status_workflow_executions(self): with self.assertRaises(ValueError): self.weq.list_workflow_executions( "INVALID_STATUS", self.domain.name, start_oldest_date=int(datetime_timestamp(past_day(3))) )
def test_list_invalid_status_workflow_executions(self): with self.assertRaises(ValueError): self.weq.list_workflow_executions( "INVALID_STATUS", self.domain.name, start_oldest_date=int(datetime_timestamp(past_day(3))), )
def mock_describe_activity_type(*args, **kwargs): override_data = kwargs.pop('override_data', {}) response = { "configuration": { "defaultTaskHeartbeatTimeout": "300", "defaultTaskList": { "name": "mocked-task-list" }, "defaultTaskScheduleToCloseTimeout": "300", "defaultTaskScheduleToStartTimeout": "300", "defaultTaskStartToCloseTimeout": "300" }, "typeInfo": { "activityType": { "name": "mocked-activity-type", "version": "0.1" }, "creationDate": datetime_timestamp(past_day(30)), "deprecationDate": datetime_timestamp(datetime.now()), "description": "mocked-description", "status": REGISTERED } } response.update(override_data) return response
def all( self, status=WorkflowExecution.STATUS_OPEN, start_oldest_date=MAX_WORKFLOW_AGE, *args, **kwargs ): """Fetch every workflow executions during the last `start_oldest_date` days, with `status` :param status: Workflow executions status filter :type status: swf.models.WorkflowExecution.{STATUS_OPEN, STATUS_CLOSED} :param start_oldest_date: Specifies the oldest start/close date to return. :type start_oldest_date: integer (days) :returns: workflow executions objects list :rtype: list A typical amazon response looks like: .. code-block:: json { "executionInfos": [ { "cancelRequested": "boolean", "closeStatus": "string", "closeTimestamp": "number", "execution": { "runId": "string", "workflowId": "string" }, "executionStatus": "string", "parent": { "runId": "string", "workflowId": "string" }, "startTimestamp": "number", "tagList": [ "string" ], "workflowType": { "name": "string", "version": "string" } } ], "nextPageToken": "string" } """ start_oldest_date = datetime_timestamp(past_day(start_oldest_date)) return [ self.to_WorkflowExecution(self.domain, wfe) for wfe in self._list_items( status, self.domain.name, start_oldest_date=int(start_oldest_date) ) ]
def all(self, status=WorkflowExecution.STATUS_OPEN, start_oldest_date=30, *args, **kwargs): """Fetch every workflow executions during the last `start_oldest_date` days, with `status` :param status: Workflow executions status filter :type status: swf.models.WorkflowExecution.{STATUS_OPEN, STATUS_CLOSED} :param start_oldest_date: Specifies the oldest start/close date to return. :type start_oldest_date: integer (days) :returns: workflow executions objects list :rtype: list A typical amazon response looks like: .. code-block:: json { "executionInfos": [ { "cancelRequested": "boolean", "closeStatus": "string", "closeTimestamp": "number", "execution": { "runId": "string", "workflowId": "string" }, "executionStatus": "string", "parent": { "runId": "string", "workflowId": "string" }, "startTimestamp": "number", "tagList": [ "string" ], "workflowType": { "name": "string", "version": "string" } } ], "nextPageToken": "string" } """ start_oldest_date = datetime_timestamp(past_day(start_oldest_date)) return [self.to_WorkflowExecution(self.domain, wfe) for wfe in self._list_items( status, self.domain.name, start_oldest_date=int(start_oldest_date))]
def test_list_open_workflows_executions_with_start_oldest_date(self): with patch.object(self.weq.connection, 'list_open_workflow_executions', mock_list_open_workflow_executions): we = self.weq.list_workflow_executions( WorkflowExecution.STATUS_OPEN, self.domain.name, start_oldest_date=int(datetime_timestamp(past_day(3)))) self.assertIsNotNone(we) self.assertIsInstance(we, dict) self.assertTrue(we['executionInfos'][0]['executionStatus'] == WorkflowExecution.STATUS_OPEN)
def test_list_closed_workflows_executions(self): with patch.object( self.weq.connection, 'list_closed_workflow_executions', mock_list_closed_workflow_executions ): we = self.weq.list_workflow_executions( WorkflowExecution.STATUS_CLOSED, self.domain.name, start_oldest_date=int(datetime_timestamp(past_day(3))) ) self.assertIsNotNone(we) self.assertIsInstance(we, dict) self.assertTrue(we['executionInfos'][0]['executionStatus'] == WorkflowExecution.STATUS_CLOSED)
def test_list_closed_workflows_executions(self): with patch.object( self.weq.connection, "list_closed_workflow_executions", mock_list_closed_workflow_executions, ): we = self.weq.list_workflow_executions( WorkflowExecution.STATUS_CLOSED, self.domain.name, start_oldest_date=int(datetime_timestamp(past_day(3))), ) self.assertIsNotNone(we) self.assertIsInstance(we, dict) self.assertTrue(we["executionInfos"][0]["executionStatus"] == WorkflowExecution.STATUS_CLOSED)
def mock_list_activity_types(*args, **kwargs): override_data = kwargs.pop("override_data", {}) response = { "typeInfos": [{ "activityType": { "name": "mocked-activity-type", "version": "0.1" }, "creationDate": datetime_timestamp(past_day(30)), "deprecationDate": datetime_timestamp(datetime.now()), "description": "mocked-description", "status": REGISTERED, }] } response.update(override_data) return response
def mock_list_activity_types(*args, **kwargs): override_data = kwargs.pop('override_data', {}) response = { "typeInfos": [ { "activityType": { "name": "mocked-activity-type", "version": "0.1" }, "creationDate": datetime_timestamp(past_day(30)), "deprecationDate": datetime_timestamp(datetime.now()), "description": "mocked-description", "status": REGISTERED } ] } response.update(override_data) return response
def filter( self, status=WorkflowExecution.STATUS_OPEN, tag=None, workflow_id=None, workflow_type_name=None, workflow_type_version=None, *args, **kwargs ): """Filters workflow executions based on kwargs provided criteras :param status: workflow executions with provided status will be kept. Valid values are: * ``swf.models.WorkflowExecution.STATUS_OPEN`` * ``swf.models.WorkflowExecution.STATUS_CLOSED`` :type status: string :param tag: workflow executions containing the tag will be kept :type tag: String :param workflow_id: workflow executions attached to the id will be kept :type workflow_id: String :param workflow_type_name: workflow executions attached to the workflow type with provided name will be kept :type workflow_type_name: String :param workflow_type_version: workflow executions attached to the workflow type of the provided version will be kept :type workflow_type_version: String **Be aware that** querying over status allows the usage of statuses specific kwargs * STATUS_OPEN :param start_latest_date: latest start or close date and time to return (in days) :type start_latest_date: int * STATUS_CLOSED :param start_latest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_latest_date: int :param start_oldest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_oldest_date: int :param close_latest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_latest_date: int :param close_oldest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_oldest_date: int :param close_status: must match the close status of an execution for it to meet the criteria of this filter. Valid values are: * ``CLOSE_STATUS_COMPLETED`` * ``CLOSE_STATUS_FAILED`` * ``CLOSE_STATUS_CANCELED`` * ``CLOSE_STATUS_TERMINATED`` * ``CLOSE_STATUS_CONTINUED_AS_NEW`` * ``CLOSE_TIMED_OUT`` :type close_status: string :returns: workflow executions objects list :rtype: list """ # As WorkflowTypeQuery has to be built against a specific domain # name, domain filter is disposable, but not mandatory. invalid_kwargs = self._validate_status_parameters(status, kwargs) if invalid_kwargs: err_msg = "Invalid keyword arguments supplied: {}".format( ", ".join(invalid_kwargs) ) raise InvalidKeywordArgumentError(err_msg) if status == WorkflowExecution.STATUS_OPEN: oldest_date = kwargs.pop("oldest_date", MAX_WORKFLOW_AGE) else: # The SWF docs on ListClosedWorkflowExecutions state that: # # "startTimeFilter and closeTimeFilter are mutually exclusive" # # so we must figure out if we have to add a default value for # start_oldest_date or not. if "close_latest_date" in kwargs or "close_oldest_date" in kwargs: default_oldest_date = None else: default_oldest_date = MAX_WORKFLOW_AGE oldest_date = kwargs.pop("start_oldest_date", default_oldest_date) # Compute a timestamp from the delta in days we got from params # If oldest_date is blank at this point, it's because we didn't want # it, so let's leave it blank and assume the user provided an other # time filter. if oldest_date: start_oldest_date = int(datetime_timestamp(past_day(oldest_date))) else: start_oldest_date = None return [ self.to_WorkflowExecution(self.domain, wfe) for wfe in self._list_items( *args, domain=self.domain.name, status=status, workflow_id=workflow_id, workflow_name=workflow_type_name, workflow_version=workflow_type_version, start_oldest_date=start_oldest_date, tag=tag, **kwargs ) ]
def filter(self, domain=None, status=WorkflowExecution.STATUS_OPEN, tag=None, workflow_id=None, workflow_type_name=None, workflow_type_version=None, *args, **kwargs): """Filters workflow executions based on kwargs provided criteras :param domain_name: workflow executions attached to domain with provided domain_name will be kept :type domain_name: String :param status: workflow executions with provided status will be kept. Valid values are: * ``swf.models.WorkflowExecution.STATUS_OPEN`` * ``swf.models.WorkflowExecution.STATUS_CLOSED`` :type status: string :param tag: workflow executions containing the tag will be kept :type tag: String :param workflow_id: workflow executions attached to the id will be kept :type workflow_id: String :param workflow_type_name: workflow executions attached to the workflow type with provided name will be kept :type workflow_type_name: String :param workflow_type_version: workflow executions attached to the workflow type of the provided version will be kept :type workflow_type_version: String **Be aware that** querying over status allows the usage of statuses specific kwargs * STATUS_OPEN :param start_latest_date: latest start or close date and time to return (in days) :type start_latest_date: int * STATUS_CLOSED :param start_latest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_latest_date: int :param start_oldest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_oldest_date: int :param close_latest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_latest_date: int :param close_oldest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_oldest_date: int :param close_status: must match the close status of an execution for it to meet the criteria of this filter. Valid values are: * ``CLOSE_STATUS_COMPLETED`` * ``CLOSE_STATUS_FAILED`` * ``CLOSE_STATUS_CANCELED`` * ``CLOSE_STATUS_TERMINATED`` * ``CLOSE_STATUS_CONTINUED_AS_NEW`` * ``CLOSE_TIMED_OUT`` :type close_status: string :returns: workflow executions objects list :rtype: list """ # As WorkflowTypeQuery has to be built against a specific domain # name, domain filter is disposable, but not mandatory. domain = domain or self.domain.name invalid_kwargs = self._validate_status_parameters(status, kwargs) if invalid_kwargs: err_msg = 'Invalid keyword arguments supplied: {}'.format( ', '.join(invalid_kwargs)) raise InvalidKeywordArgumentError(err_msg) if status == WorkflowExecution.STATUS_OPEN: oldest_date = kwargs.get('oldest_date', 30) else: oldest_date = kwargs.get('start_oldest_date', 30) start_oldest_date = datetime_timestamp(past_day(oldest_date)) return [self.to_WorkflowExecution(domain, wfe) for wfe in self._list_items(status, domain, start_oldest_date=int(start_oldest_date))]
def filter(self, status=WorkflowExecution.STATUS_OPEN, tag=None, workflow_id=None, workflow_type_name=None, workflow_type_version=None, *args, **kwargs): """Filters workflow executions based on kwargs provided criteras :param status: workflow executions with provided status will be kept. Valid values are: * ``swf.models.WorkflowExecution.STATUS_OPEN`` * ``swf.models.WorkflowExecution.STATUS_CLOSED`` :type status: string :param tag: workflow executions containing the tag will be kept :type tag: String :param workflow_id: workflow executions attached to the id will be kept :type workflow_id: String :param workflow_type_name: workflow executions attached to the workflow type with provided name will be kept :type workflow_type_name: String :param workflow_type_version: workflow executions attached to the workflow type of the provided version will be kept :type workflow_type_version: String **Be aware that** querying over status allows the usage of statuses specific kwargs * STATUS_OPEN :param start_latest_date: latest start or close date and time to return (in days) :type start_latest_date: int * STATUS_CLOSED :param start_latest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_latest_date: int :param start_oldest_date: workflow executions that meet the start time criteria of the filter are kept (in days) :type start_oldest_date: int :param close_latest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_latest_date: int :param close_oldest_date: workflow executions that meet the close time criteria of the filter are kept (in days) :type close_oldest_date: int :param close_status: must match the close status of an execution for it to meet the criteria of this filter. Valid values are: * ``CLOSE_STATUS_COMPLETED`` * ``CLOSE_STATUS_FAILED`` * ``CLOSE_STATUS_CANCELED`` * ``CLOSE_STATUS_TERMINATED`` * ``CLOSE_STATUS_CONTINUED_AS_NEW`` * ``CLOSE_TIMED_OUT`` :type close_status: string :returns: workflow executions objects list :rtype: list """ # As WorkflowTypeQuery has to be built against a specific domain # name, domain filter is disposable, but not mandatory. invalid_kwargs = self._validate_status_parameters(status, kwargs) if invalid_kwargs: err_msg = 'Invalid keyword arguments supplied: {}'.format( ', '.join(invalid_kwargs)) raise InvalidKeywordArgumentError(err_msg) if status == WorkflowExecution.STATUS_OPEN: oldest_date = kwargs.pop('oldest_date', MAX_WORKFLOW_AGE) else: # The SWF docs on ListClosedWorkflowExecutions state that: # # "startTimeFilter and closeTimeFilter are mutually exclusive" # # so we must figure out if we have to add a default value for # start_oldest_date or not. if "close_latest_date" in kwargs or "close_oldest_date" in kwargs: default_oldest_date = None else: default_oldest_date = MAX_WORKFLOW_AGE oldest_date = kwargs.pop('start_oldest_date', default_oldest_date) # Compute a timestamp from the delta in days we got from params # If oldest_date is blank at this point, it's because we didn't want # it, so let's leave it blank and assume the user provided an other # time filter. if oldest_date: start_oldest_date = int(datetime_timestamp(past_day(oldest_date))) else: start_oldest_date = None return [self.to_WorkflowExecution(self.domain, wfe) for wfe in self._list_items( *args, domain=self.domain.name, status=status, workflow_id=workflow_id, workflow_name=workflow_type_name, workflow_version=workflow_type_version, start_oldest_date=start_oldest_date, tag=tag, **kwargs )]