5

I have a two tasks.

@app.task
def run1():
    while True:
        print('run1')
        time.sleep(5)
    return


@app.task
def run2():
    while True:
        print('run2')
        time.sleep(2)
    return

How can I run these two tasks at the same time from the same console, from one command (preferably with a different number of workers).

0

1 Answer 1

8

You need to use group:

The group primitive is a signature that takes a list of tasks that should be applied in parallel.

Example from django shell:

>>> from celery import group
>>> from myapp.tasks import run1, run2
>>>
>>> run_group = group(run1.s(), run2.s())
>>> run_group()
<GroupResult: 06b3e88b-6c10-4ba5-bb32-5005c82eedfe [cc734fbd-3531-45d1-8575-64f4eff35523, 
1075e822-a6e2-4c34-8038-369613ff687d]>

For more complex usage, see the docs on group.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.