Created
May 14, 2021 05:43
-
-
Save syedjafer/1bace19820d56479b8d37b77d7b09836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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