Execute in the following order:
docker run -d -p 6379:6379 redispython celery_app.pypython send_task.py| import logging | |
| from celery import Celery | |
| logging.getLogger("celery").setLevel(logging.DEBUG) | |
| app = Celery( | |
| "myapp", # not sure if/how this matters | |
| broker="redis://localhost", # to connect to the broker | |
| backend="redis://localhost", # to be able to collect task results | |
| include=["celery_app"], # so that the add task is registered | |
| ) | |
| @app.task | |
| def add(x, y): | |
| return x + y | |
| if __name__ == "__main__": | |
| app.start(["worker"]) |
| from celery_app import add | |
| if __name__ == "__main__": | |
| # Send a task to the Celery app. | |
| result = add.delay(3, 5) | |
| # Wait for the result of the task and print it. | |
| print("Waiting for the task to complete...") | |
| result_value = result.get() | |
| print(f"Task result: {result_value}") |