Skip to content

Commit

Permalink
Merge pull request #29 from xethorn/mo-15-feb-add-run
Browse files Browse the repository at this point in the history
Switch `tasks` with `run`.
  • Loading branch information
xethorn committed Feb 18, 2015
2 parents bf35e99 + b284cd5 commit c10f4aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ test_activity_1 = create(
test_activity_2 = create(
name='activity_2',
requires=[test_activity_1],
tasks=runner.Async(
run=runner.Async(
lambda activity, context: print('activity_2_task_1'),
lambda activity, context: print('activity_2_task_2')))

test_activity_3 = create(
name='activity_3',
requires=[test_activity_1],
tasks=runner.Sync(
run=runner.Sync(
lambda activity, context: print('activity_3')))

test_activity_4 = create(
name='activity_4',
requires=[test_activity_3, test_activity_2],
tasks=runner.Sync(
lambda activity, context: print('activity_4')))
run=runner.Sync(
lambda activity, context: print('activity_4')))
```

### Application architecture
Expand Down
8 changes: 4 additions & 4 deletions example/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ def activity_failure(activity, context):

test_activity_1 = create(
name='o',
tasks=runner.Sync(
run=runner.Sync(
lambda activity, context: logger.debug('activity_1')))

test_activity_2 = create(
name='activity_2',
requires=[test_activity_1],
tasks=runner.Async(
run=runner.Async(
lambda activity, context: logger.debug('activity_2_task_1'),
lambda activity, context: logger.debug('activity_2_task_2')))

test_activity_3 = create(
name='activity_3',
retry=10,
requires=[test_activity_1],
tasks=runner.Sync(activity_failure))
run=runner.Sync(activity_failure))

test_activity_4 = create(
name='activity_4',
requires=[test_activity_3, test_activity_2],
tasks=runner.Sync(
run=runner.Sync(
lambda activity, context: logger.debug('activity_4')))
21 changes: 14 additions & 7 deletions garcon/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# Name of your activity
name='activity_name',
# List of tasks (here we use the Sync runner)
tasks=runner.Sync(task1),
# List of tasks to run (here we use the Sync runner)
run=runner.Sync(task1),
# No requires since it's the first one. Later in your flow, if you have
# a dependency, just use the variable that contains the activity.
Expand Down Expand Up @@ -149,13 +149,13 @@ def run(self):
return True

def execute_activity(self, context):
"""Execute the tasks within the activity.
"""Execute the runner.
Args:
context (dict): The flow context.
"""

return self.tasks.execute(self, context)
return self.runner.execute(self, context)

def hydrate(self, data):
"""Hydrate the task with information provided.
Expand All @@ -169,7 +169,13 @@ def hydrate(self, data):
self.requires = getattr(self, 'requires', []) or data.get('requires')
self.retry = getattr(self, 'retry', None) or data.get('retry', 0)
self.task_list = self.task_list or data.get('task_list')
self.tasks = getattr(self, 'tasks', []) or data.get('tasks')

# The previous way to create an activity was to fill a `tasks` param,
# which is not `run`.
self.runner = (
getattr(self, 'runner', None) or
data.get('run') or data.get('tasks'))

self.generators = getattr(
self, 'generators', None) or data.get('generators')

Expand Down Expand Up @@ -221,7 +227,7 @@ def timeout(self):
int: Task list timeout.
"""

return self.tasks.timeout
return self.runner.timeout


class ActivityWorker():
Expand Down Expand Up @@ -289,7 +295,8 @@ def wrapper(**options):
requires=options.get('requires', []),
retry=options.get('retry'),
task_list=domain + '_' + options.get('name'),
tasks=options.get('tasks', [])
tasks=options.get('tasks'),
run=options.get('run'),
))
return activity
return wrapper
Expand Down
2 changes: 1 addition & 1 deletion tests/test_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_execute_activity(monkeypatch):
custom_task = MagicMock(return_value=resp)

current_activity = activity.Activity()
current_activity.tasks = runner.Sync(custom_task)
current_activity.runner = runner.Sync(custom_task)

val = current_activity.execute_activity(dict(foo='bar'))

Expand Down

0 comments on commit c10f4aa

Please sign in to comment.