Note: Each one of us have their own use-cases, this talk is primarily to understand whole ecosystem of tasks. Because we use Celery hence I'd be using celery to relate to example.
pip install celery
BROKER_URL = 'amqp://guest:guest@localhost:5672/' CELERY_RESULT_BACKEND = "amqp" CELERY_IMPORTS = ("tasks",)
celery = Celery('tasks') celery.config_from_object('celeryconfig')
@celery.task def test_demo(): print "name" return True
@celery.task def add(a1, a2): a3 = a1 + a2 print a3 return a3
celery -A tasks worker --loglevel=info -c 1
from tasks import * s = add.delay(2,3) s.status s.result
Scheduling tasks from UI
Execute trees of tasks asynchronously in a particular order
from celery_tasktree import task_with_callbacks, TaskTree
@task_with_callbacks def some_action(...): ...
def execute_actions():
tree = TaskTree()
task0 = tree.add_task(some_action, args=[...], kwargs={...})
task1 = tree.add_task(some_action, args=[...], kwargs={...})
task10 = task1.add_task(some_action, args=[...], kwargs={...})
task11 = task1.add_task(some_action, args=[...], kwargs={...})
task110 = task11.add_task(some_action, args=[...], kwargs={...})
async_result = tree.apply_async()
return async_result