Last active
August 29, 2015 14:16
-
-
Save xethorn/09d891c4746383242dcd to your computer and use it in GitHub Desktop.
Garcon - Context Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto.swf.layer2 as swf | |
from garcon import activity | |
from garcon import runner | |
from garcon import task | |
domain = 'dev' | |
name = 'context_example' | |
create = activity.create(domain, name) | |
@task.decorate() | |
def bootstrap(): | |
# The bootstrap is just here to provide more information | |
# in the context which we can use later on. It's for the | |
# purpose of this demo. | |
return dict(user_id='<user id>', email='<email id>') | |
@task.decorate() | |
def process_payment_for_user(user_id): | |
# Process the payment for a specific user | |
return dict(payment_id='<payment id>') | |
@task.decorate() | |
def send_email_to_user(user_id, email, payment_id): | |
# Send some information to the user about the payment id | |
print('Email sent to {email} ({user_id}) about {payment_id}'.format( | |
user_id=user_id, | |
payment_id=payment_id, | |
email=email)) | |
return | |
initialize = create( | |
name='initialize', | |
tasks=runner.Sync( | |
bootstrap.fill())) | |
process = create( | |
name='process_payment', | |
requires=[initialize], | |
tasks=runner.Sync( | |
# The bootstrap returns `user_id` in the context. The value will be | |
# captured from the context then sent to the activity. | |
process_payment_for_user.fill(user_id='user_id'))) | |
finish_payment = create( | |
name='finish_payment', | |
requires=[process], | |
tasks=runner.Sync(send_email_to_user.fill( | |
# Same as above except this time, we're trying to get more information | |
# from the context. | |
user_id='user_id', | |
payment_id='payment_id', | |
email='email'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment