Skip to content

Commit

Permalink
Add names for workflow.
Browse files Browse the repository at this point in the history
SWF has a limit of 100 domains. To make sure we do not reach this limit,
we will use a slightly different approach where domain can be used by
more than one workflow - and have those workflow be more specific
by providing a name
  • Loading branch information
xethorn committed Mar 2, 2015
1 parent b213769 commit ca88af3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions example/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
deciderworker = decider.DeciderWorker(test_flow)

swf.WorkflowType(
name=test_flow.domain + '_decider', domain=test_flow.domain,
version='1.0', task_list=test_flow.domain + '_decider').start()
name=test_flow.name, domain=test_flow.domain,
version='1.0', task_list=test_flow.name).start()

Thread(target=activity.ActivityWorker(test_flow).run).start()
while(True):
Expand Down
3 changes: 2 additions & 1 deletion example/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
logger = logging.getLogger(__name__)

domain = 'dev'
create = activity.create(domain)
name = 'workflow_sample'
create = activity.create(domain, name)


def activity_failure(context, activity):
Expand Down
10 changes: 7 additions & 3 deletions garcon/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def worker_runner(worker):
continue


def create(domain):
def create(domain, name):
"""Helper method to create Activities.
The helper method simplifies the creation of an activity by setting the
Expand All @@ -320,13 +320,17 @@ def create(domain):

def wrapper(**options):
activity = Activity()
activity_name = '{name}_{activity}'.format(
name=name,
activity=options.get('name'))

activity.hydrate(dict(
domain=domain,
name=options.get('name'),
name=activity_name,
generators=options.get('generators', []),
requires=options.get('requires', []),
retry=options.get('retry'),
task_list=domain + '_' + options.get('name'),
task_list=activity_name,
tasks=options.get('tasks'),
run=options.get('run'),
))
Expand Down
3 changes: 1 addition & 2 deletions garcon/decider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def __init__(self, flow, register=True):

self.flow = flow
self.domain = flow.domain
self.task_list = flow.domain + '_decider'
self.version = '1.0'
self.activities = activity.find_workflow_activities(flow)

self.task_list = flow.name
super(DeciderWorker, self).__init__()

if register:
Expand Down
24 changes: 12 additions & 12 deletions tests/fixtures/decider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
'eventId': 4,
'eventTimestamp': 1419350960.945,
'eventType': 'DecisionTaskCompleted'},
{'activityTaskScheduledEventAttributes': {'activityId': 'activity_1-1',
'activityType': {'name': 'activity_1', 'version': '1.0'},
{'activityTaskScheduledEventAttributes': {'activityId': 'workflow_name_activity_1-1',
'activityType': {'name': 'workflow_name_activity_1', 'version': '1.0'},
'decisionTaskCompletedEventId': 4,
'heartbeatTimeout': '600',
'input': 'json object',
'scheduleToCloseTimeout': '3900',
'scheduleToStartTimeout': '300',
'startToCloseTimeout': '3600',
'taskList': {'name': 'garcon_activity_1'}},
'taskList': {'name': 'garcon_workflow_name_activity_1'}},
'eventId': 5,
'eventTimestamp': 1419350960.945,
'eventType': 'ActivityTaskScheduled'},
Expand All @@ -53,27 +53,27 @@
'eventId': 10,
'eventTimestamp': 1419351026.232,
'eventType': 'DecisionTaskCompleted'},
{'activityTaskScheduledEventAttributes': {'activityId': 'activity_2-1',
'activityType': {'name': 'activity_2', 'version': '1.0'},
{'activityTaskScheduledEventAttributes': {'activityId': 'workflow_name_activity_2-1',
'activityType': {'name': 'workflow_name_activity_2', 'version': '1.0'},
'decisionTaskCompletedEventId': 10,
'heartbeatTimeout': '600',
'input': 'json object',
'scheduleToCloseTimeout': '3900',
'scheduleToStartTimeout': '300',
'startToCloseTimeout': '3600',
'taskList': {'name': 'garcon_activity_2'}},
'taskList': {'name': 'garcon_workflow_name_activity_2'}},
'eventId': 11,
'eventTimestamp': 1419351026.232,
'eventType': 'ActivityTaskScheduled'},
{'activityTaskScheduledEventAttributes': {'activityId': 'activity_3-1',
'activityType': {'name': 'activity_3', 'version': '1.0'},
{'activityTaskScheduledEventAttributes': {'activityId': 'workflow_name_activity_3-1',
'activityType': {'name': 'workflow_name_activity_3', 'version': '1.0'},
'decisionTaskCompletedEventId': 10,
'heartbeatTimeout': '600',
'input': 'json object',
'scheduleToCloseTimeout': '3900',
'scheduleToStartTimeout': '300',
'startToCloseTimeout': '3600',
'taskList': {'name': 'garcon_activity_3'}},
'taskList': {'name': 'garcon_workflow_name_activity_3'}},
'eventId': 12,
'eventTimestamp': 1419351026.232,
'eventType': 'ActivityTaskScheduled'},
Expand Down Expand Up @@ -119,15 +119,15 @@
'eventId': 22,
'eventTimestamp': 1419351027.381,
'eventType': 'DecisionTaskCompleted'},
{'activityTaskScheduledEventAttributes': {'activityId': 'activity_4-1',
'activityType': {'name': 'activity_4', 'version': '1.0'},
{'activityTaskScheduledEventAttributes': {'activityId': 'workflow_name_activity_4-1',
'activityType': {'name': 'workflow_name_activity_4', 'version': '1.0'},
'decisionTaskCompletedEventId': 22,
'heartbeatTimeout': '600',
'input': 'json object',
'scheduleToCloseTimeout': '3900',
'scheduleToStartTimeout': '300',
'startToCloseTimeout': '3600',
'taskList': {'name': 'garcon_activity_4'}},
'taskList': {'name': 'garcon_workflow_name_activity_4'}},
'eventId': 23,
'eventTimestamp': 1419351027.381,
'eventType': 'ActivityTaskScheduled'},
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/flows/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


domain = 'dev'
create = activity.create(domain)
name = 'workflow_name'
create = activity.create(domain, name)

activity_1 = create(
name='activity_1',
Expand Down

0 comments on commit ca88af3

Please sign in to comment.