Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created May 14, 2021 05:43
Show Gist options
  • Select an option

  • Save syedjafer/1bace19820d56479b8d37b77d7b09836 to your computer and use it in GitHub Desktop.

Select an option

Save syedjafer/1bace19820d56479b8d37b77d7b09836 to your computer and use it in GitHub Desktop.
from celery import Celery
from celery import chain
import time
app = Celery(name="tasks",
broker="redis://localhost:6379/0",
backend="db+sqlite:///db+sqlite3"
)
@app.task
def add(num_1, num_2):
time.sleep(15)
return num_1 + num_2
res = chain(add.s(1, 2), add.s(3), add.s(9)).apply_async()
# OR
# res2 = (add.s(1, 2) | add.s(3)).apply_async()
if res.ready():
print(res.get()) # add.s(1, 2), add.s(3), add.s(9)
print(res.parent.get()) # add.s(1, 2), add.s(3)
print(res.parent.parent.get()) # add.s(1, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment