Last active
          August 29, 2015 14:16 
        
      - 
      
- 
        Save xethorn/2cefcc85d5093b12d065 to your computer and use it in GitHub Desktop. 
    Garcon - Country flow
  
        
  
    
      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 | |
| import random | |
| domain = 'dev' | |
| name = 'country_flow' | |
| create = activity.create(domain, name) | |
| def country_generator(context): | |
| # We limit this so you can more easily see the failures / retries. | |
| total_countries = 6 | |
| for country_id in range(1, total_countries): | |
| yield {'generator.country_id': country_id} | |
| @task.decorate() | |
| def unstable_country_task(activity, country_id): | |
| num = int(random.random() * 4) | |
| base = 'activity_2_country_id_{country_id}'.format( | |
| country_id=country_id) | |
| if num == 3: | |
| # Make the task randomly fail. | |
| print(base, 'has failed') | |
| raise Exception('fails') | |
| print(base, 'has succeeded') | |
| test_activity_1 = create( | |
| name='activity_1', | |
| tasks=runner.Sync( | |
| lambda context, activity: print('activity_1'))) | |
| test_activity_2 = create( | |
| name='activity_2', | |
| requires=[test_activity_1], | |
| generators=[ | |
| country_generator], | |
| retry=3, | |
| tasks=runner.Sync( | |
| unstable_country_task.fill(country_id='generator.country_id'))) | |
| test_activity_3 = create( | |
| name='activity_3', | |
| requires=[test_activity_2], | |
| tasks=runner.Sync( | |
| lambda context, activity: print('end of flow'))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment