|
| 1 | +# Celery easy workkflow |
| 2 | + |
| 3 | +## commands : |
| 4 | + |
| 5 | +> pip install -r requirements.txt |
| 6 | +
|
| 7 | +> https://github.com/celery/celery/ |
| 8 | +
|
| 9 | +> celery -A test_app.celery worker --pool=solo --loglevel=info |
| 10 | +
|
| 11 | +> celery -A test_app.celery worker --loglevel=info |
| 12 | +
|
| 13 | +<br /> |
| 14 | + |
| 15 | +## Overview : |
| 16 | +``` |
| 17 | +Getting started with celery from strach using redis as broker and postgres as backend to store task results with vanilla pythhon. Had to make to make this document because it was quite confusing . |
| 18 | +``` |
| 19 | + |
| 20 | +### 1. Setup : Redis |
| 21 | +``` |
| 22 | +If you are on windows : |
| 23 | +1. Activate wsl |
| 24 | +2. Install any sub linux system or [Ubunut TLS](https://www.microsoft.com/store/productId/9MTTCL66CPXJ ) |
| 25 | +3. Open Linux cli follow commands : |
| 26 | + > sudo apt-add-repository ppa:redislabs/redis |
| 27 | + > suo apt-get update |
| 28 | + > suo apt-get upgrade |
| 29 | + > sudo apt-get install redis-server |
| 30 | + > redis-server --version |
| 31 | + > redis-server |
| 32 | +
|
| 33 | +4. Open another linux terminal : |
| 34 | + > redis-cli |
| 35 | + > set name nishant |
| 36 | + > get name |
| 37 | +
|
| 38 | +5. Redis is now ready to use |
| 39 | +
|
| 40 | +6. Optional step to view data stored : |
| 41 | +> https://redis.io/download/#redis-stack-downloads |
| 42 | +
|
| 43 | +7. CELERY_BROKER_URL = 'redis://127.0.0.1:6379/0' |
| 44 | +``` |
| 45 | + |
| 46 | +<br /> |
| 47 | + |
| 48 | +### 2. Setup : Posgres |
| 49 | +``` |
| 50 | +1 . Create a database in postgres |
| 51 | +
|
| 52 | +
|
| 53 | +Celery backend url systax : <database_identifier>://<postgres_username>:<password>@<hostname>/<database_name> |
| 54 | +
|
| 55 | +My local settings : |
| 56 | +CELERY_BACKEND_URL = 'db+postgresql+psycopg2://postgres:root@localhost/celery-db' |
| 57 | +``` |
| 58 | + |
| 59 | +<br /> |
| 60 | + |
| 61 | +### 3. Setup : Celery |
| 62 | +``` |
| 63 | +Celery command : |
| 64 | +
|
| 65 | +1. Open a terminal in same project |
| 66 | +syntax > celery -A <your_python_file>.<celery_app> worker |
| 67 | + > celery -A test_app.celery_app worker --pool=solo --loglevel=info |
| 68 | +
|
| 69 | +2. Open Another Terminal : |
| 70 | +
|
| 71 | +from task_app import factorial |
| 72 | +
|
| 73 | +>> ans = factorial.delay(10) |
| 74 | +>> ans._get_task_meta() |
| 75 | +>> factorial.name |
| 76 | +
|
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +> https://celeryproject.readthedocs.io/zh_CN/latest/userguide/tasks.html |
| 81 | +
|
| 82 | +> https://stackoverflow.com/questions/63901790/celery-how-to-get-task-name-by-task-id |
0 commit comments