Code Monkey home page Code Monkey logo

garcon's Introduction

BuildStatus Downloads CoverageStatus

Lightweight library for AWS SWF.

Garcon deals with easy going clients and kitchens. It takes orders from clients (deciders), and send them to the kitchen (activities). Difficult clients and kitchens can be handled directly by the restaurant manager.

Requirements

  • Python 3.5, 3.6, 3.7, 3.8 (tested)
  • Boto3 (tested)

Goal

The goal of this library is to allow the creation of Amazon Simple Workflow without the need to worry about the orchestration of the different activities and building out the different workers. This framework aims to help simple workflows. If you have a more complex case, you might want to use directly boto.

Code sample

The code sample shows a workflow where a user enters a coffee shop, orders a coffee and a chocolate chip cookie. All ordered items are prepared and completed, the user pays the order, receives the ordered items, then leave the shop.

The code below represents the workflow decider. For the full code sample, see the example.

enter = schedule('enter', self.create_enter_coffee_activity)
enter.wait()

total = 0
for item in ['coffee', 'chocolate_chip_cookie']:
    activity_name = 'order_{item}'.format(item=item)
    activity = schedule(activity_name,
        self.create_order_activity,
        input={'item': item})
    total += activity.result.get('price')

pay_activity = schedule(
    'pay', self.create_payment_activity,
    input={'total': total})

get_order = schedule('get_order', self.create_get_order_activity)

# Waiting for paying and getting the order to complete before
# we let the user leave the coffee shop.
pay_activity.wait(), get_order.wait()
schedule('leave_coffee_shop', self.create_leave_coffee_shop)

Application architecture

.
├── cli.py # Instantiate the workers
├── flows # All your application flows.
│   ├── __init__.py
│   └── example.py # Should contain a structure similar to the code sample.
├── tasks # All your tasks
│   ├── __init__.py
│   └── s3.py # Task that focuses on s3 files.
└── task_example.py # Your different tasks.

Trusted by

The Orchard Sony Music DataArt

Contributors

  • Michael Ortali (Author)
  • Adam Griffiths
  • Raphael Antonmattei
  • John Penner

garcon's People

Contributors

adamlwgriffiths avatar bakuutin avatar codacy-badger avatar emersin avatar glennyonemitsu avatar rantonmattei avatar someboredkiddo avatar xethorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

garcon's Issues

Add better support for all the different timeouts

Today, only two timeouts are supported (instead of many.) We need to add support for timeouts and also allow overrides.

Notes for activity timeouts:

schedule_to_close_timeout = start_to_close_timeout + schedule_to_start_timeout
# schedule_to_start_timeout can be set by the `create` method (if undefined, 5 will be used.)

More information on the timeouts are in the Flow Documentation.

Generators are not able to get new dynamically added values in the context from previous tasklist

Generators are only able to get context that is set initially. They cannot access context that is dynamically set by the task list before. For example, I have a bootstrap task which get context from a config file, later on, i have another task which query database and update the context from query result right after; The generator in the next task list is not able to get the updated context.

Optimize input

The decider is currently getting all the results from all the tasks, and sends them as an input. SWF has a limit of 32k characters for input/output.

  • Have the decider look at the activity and ask for all the required context keys
  • Activity can look at all the tasks and get from them the context keys.
  • Pluck from the context the required values, and send them as input.

Michael is the founder of CreativeList. Learn more about Creativelist - The Creator Search Engine. It's a search engine specialized in finding designers, photographers, or any type of creatives in big cities like new york, los angeles, san francisco or near you.

Add ability to write the workflow

Problem

Today, the decider is generated automatically which simplifies how to write simple workflows. However, for workflows that are more complex to write (for instance: workflows with optional activities), it is a lot more difficult to create those using Garcon.

Goal

Add a set of features that make it easy to write more complex workflows (support for loops, conditionals, activity responses).

Draft

  • schedule(activity, requires=[], **local_context). The schedule method is responsible for verifying that the activity instance have not been scheduled yet and all the dependencies have completed before scheduling this activity. Schedule can take a local context. This method returns a Result object. Requires is a list of activity that should have completed.
  • Result: Representation of a scheduled event. This representation contains the state of the activity, the input of the activity, if completed the response of the activity. Scheduled events can be used as a way to trigger the following activities. Trying to get a value of the response or verifying if a result has processed throws an exception which triggers self.complete on the decider.

Code Sample

import boto.swf.layer2 as swf

from garcon import activity
from garcon import runner
import logging
import random


logger = logging.getLogger(__name__)

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

TestActivity1 = create_activity(
    name='o',
    run=runner.Sync(
        lambda context, activity: logger.debug('activity_1')))

TestActivity2 = create_activity(
    name='activity_2',
    run=runner.Async(
        lambda context, activity: logger.debug('activity_2_task_1'),
        lambda context, activity: logger.debug('activity_2_task_2')))

TestActivity3 = create_activity(
    name='activity_3',
    retry=10,
    run=runner.Sync(
        lambda context, activity: logger.debug('activity_3')))

TestActivity4 = create_activity(
    name='activity_4',
    run=runner.Sync(
        lambda context, activity: logger.debug('activity_4')))


def run(execution, schedule):
    activity_1 = schedule(TestActivity)
    activity_2 = schedule(TestActivity2)
    if activity_1: 
       logger.debug('Activity1 has completed')
    activity_3 = schedule(TestActivity3, requires=(activity_1, activity_2))
    activity_4 = schedule(TestActivity4, requires=(activity_3,))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.