Skip to content

Instantly share code, notes, and snippets.

@jalavik
Created March 30, 2015 14:17
Show Gist options
  • Save jalavik/82ff4a4e282289810c9f to your computer and use it in GitHub Desktop.
Save jalavik/82ff4a4e282289810c9f to your computer and use it in GitHub Desktop.
workflow sample in Celery
"""
Install deps:
$ pip install workflow
$ pip install celery[redis]
Run worker to listen to jobs:
$ cd path/to/this/file/
$ celery -A workflow_sample worker --loglevel=info
Run a job
$ python workflow_sample.py
You will see output of the last task.
"""
from celery import Celery
app = Celery('workflow_sample', broker='redis://localhost:6379/0')
def add(obj, eng):
obj["value"] += 2
def print_res(obj, eng):
print obj.get("value")
flow = [add, print_res]
@app.task
def run_workflow(data):
from workflow.engine import GenericWorkflowEngine
wfe = GenericWorkflowEngine()
wfe.setWorkflow(flow)
wfe.process(data)
if __name__ == "__main__":
run_workflow.delay([{"value": 10}, {"value": 20}, {"value": 30}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment