Skip to content

Commit

Permalink
Merge pull request #20 from phishermaan/reorganize-work-client-config
Browse files Browse the repository at this point in the history
Reorganize work client config
  • Loading branch information
quantsini committed Dec 21, 2016
2 parents 1f073e5 + e55fe36 commit cca22ee
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 273 deletions.
2 changes: 1 addition & 1 deletion py_swf/__init__.py
Expand Up @@ -4,4 +4,4 @@

__author__ = 'Henri Bai'
__email__ = 'hbai@yelp.com'
__version__ = '1.3.0'
__version__ = '1.4.0'
32 changes: 27 additions & 5 deletions py_swf/clients/workflow.py
Expand Up @@ -2,8 +2,23 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from collections import namedtuple

__all__ = ['WorkflowClient']

CountWorkflowsResult = namedtuple(
'CountWorkflowsResult',
'count truncated',
)
"""
An immutable object that stores results of counting workflows.
Wrapper around response from :meth:`~SWF.Client.count_closed_workflow_executions and
:meth:`~SWF.Client.count_open_workflow_executions.
count (integer) -- The number of workflow executions.
truncated (boolean) -- If set to true, indicates that the actual count was more than the maximum supported by this API
and the count returned is the truncated value.
"""


class WorkflowClient(object):
"""A client that provides a pythonic API for starting and terminating workflows through an SWF boto3 client.
Expand All @@ -18,7 +33,7 @@ def __init__(self, workflow_client_config, boto_client):
self.workflow_client_config = workflow_client_config
self.boto_client = boto_client

def start_workflow(self, input, id):
def start_workflow(self, input, id, workflow_name, version):
"""Enqueues and starts a workflow to SWF.
Passthrough to :meth:`~SWF.Client.start_workflow_execution`.
Expand All @@ -27,6 +42,11 @@ def start_workflow(self, input, id):
:type input: string
:param id: Freeform string that represents a unique identifier for the workflow.
:type id: string
:param workflow_name: The name of the workflow type. The combination of workflow type name and version must be
unique with in a domain.
:type workflow_name: string
:param version: The version of the workflow type.
:type version: string
:returns: An AWS generated uuid that represents a unique identifier for the run of this workflow.
:rtype: string
"""
Expand All @@ -36,8 +56,8 @@ def start_workflow(self, input, id):
workflowId=id,
input=input,
workflowType={
'name': self.workflow_client_config.workflow_name,
'version': self.workflow_client_config.workflow_version,
'name': workflow_name,
'version': version,
},
taskList={
'name': self.workflow_client_config.task_list,
Expand Down Expand Up @@ -104,11 +124,12 @@ def count_open_workflow_executions(
latest_start_date=latest_start_date,
)

return self.boto_client.count_open_workflow_executions(
response = self.boto_client.count_open_workflow_executions(
domain=self.workflow_client_config.domain,
startTimeFilter=start_time_filter_dict['startTimeFilter'],
**workflow_filter_dict
)
return CountWorkflowsResult(count=response['count'], truncated=response['truncated'])

def count_closed_workflow_executions(
self,
Expand Down Expand Up @@ -163,10 +184,11 @@ def count_closed_workflow_executions(
)
workflow_filter_dict.update(time_filter_dict)

return self.boto_client.count_closed_workflow_executions(
response = self.boto_client.count_closed_workflow_executions(
domain=self.workflow_client_config.domain,
**workflow_filter_dict
)
return CountWorkflowsResult(count=response['count'], truncated=response['truncated'])


def _build_time_filter_dict(oldest_start_date=None, latest_start_date=None, oldest_close_date=None, latest_close_date=None):
Expand Down
2 changes: 1 addition & 1 deletion py_swf/config_definitions.py
Expand Up @@ -7,7 +7,7 @@

WorkflowClientConfig = namedtuple(
'WorkflowClientConfig',
'domain workflow_name workflow_version task_list execution_start_to_close_timeout task_start_to_close_timeout',
'domain task_list execution_start_to_close_timeout task_start_to_close_timeout',
)
"""An immutable object that stores common SWF values. Used by instances of :class:`~py_swf.clients.workflow.WorkflowClient`.
"""
Expand Down
2 changes: 0 additions & 2 deletions tests/acceptance/conftest.py
Expand Up @@ -103,8 +103,6 @@ def workflow_client(boto_client, domain_name, task_list, workflow_name, version,
workflow_client_config = WorkflowClientConfig(
domain=domain_name,
task_list=task_list,
workflow_name=workflow_name,
workflow_version=version,
execution_start_to_close_timeout=5,
task_start_to_close_timeout=5,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/workflow_test.py
Expand Up @@ -25,6 +25,8 @@ def start_workflow(workflow_client, workflow_id):
meow='yes',
)),
id=workflow_id,
workflow_name='test',
version='0.1'
)


Expand Down

0 comments on commit cca22ee

Please sign in to comment.