Code Monkey home page Code Monkey logo

pyswf's Introduction

py_swf

https://travis-ci.org/Yelp/pyswf.svg?branch=master https://coveralls.io/repos/github/Yelp/pyswf/badge.svg?branch=master Documentation Status

py_swf is a library that provides a pythonic way to interact with the boto3 SWF client. It provides a thin client above boto3 and tries to provide the same API as boto3's SWF client. This library tries to group the API calls into SWF's framework of deciders, activity runners, and a client that can initiate and terminate workflows. More information on inputs to boto3 can be found in the boto3 :class:`~SWF.Client` class.

The library provides 4 clients:
  • A client that allows starting and force-termination of workflows.
  • A client that can poll for decision tasks and respond to decision tasks.
  • A client that can poll for activity tasks and respond to activity tasks.
  • A client that can perform registration of workflows in SWF.

Consumers of this library are expected to write their own daemons that enact business logic.

Example daemon that listens on decision tasks

import boto3
from py_swf.config_definitions import DecisionConfig
from py_swf.clients.decision import DecisionClient

boto_client =  boto3.Session(...).client('swf')
decision_config = DecisionConfig(...)

client = DecisionClient(decision_config, boto_client)

while True:
        task = client.poll()

        ... = perform_decision_task(task)

        client.finish_decision_with_activity(
                task.task_token,
                ...
        )

The heart of the daemon is the :class:`~py_swf.clients.decision.DecisionClient`. You must provide a valid bare boto3 client, and :class:`~py_swf.config_definitions.DecisionConfig` which represents common SWF inputs, such as domain, and some timeouts.

Likewise, you must implement an activity runner:

import boto3
from py_swf.config_definitions import ActivityTaskConfig
from py_swf.clients.activity_task import ActivityTaskClient

boto_client =  boto3.Session(...).client('swf')
activity_task_config = ActivityTaskConfig(...)

client = ActivityTaskClient(decision_config, boto_client)

while True:
        task = client.poll()

        result = perform_activity_task(task.input)

        client.finish(
                task_token=task.task_token,
                result=result,
        )

Activity task runners are very similar to deciders. However, they don't have any information of the workflow, and only perform one task given an input and responds with an output.

pyswf's People

Contributors

phishermaan avatar quantsini avatar jwien001 avatar bxm156 avatar

Watchers

 avatar

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.