Using watchfiles and exec commands in bin scripts

drew/tilt-local-dev
Drew Bednar 2 years ago
parent aa3dc3dba4
commit 62da4a19ac

@ -1,3 +1,18 @@
# FastAPI and Celery # FastAPI and Celery
Learning distributed task queues by doing. Since it's a greenfield project this also uses a newer async web framework. Learning distributed task queues by doing. Since it's a greenfield project this also uses a newer async web framework.
## Debugging Celery
### Check results in redis result backend
```
docker-compose exec redis sh
redis-cli
KEYS celery*
MGET celery-task-meta-<UID of Task>
```
### Checking results in Flower
`0.0.0.0:

@ -4,4 +4,4 @@ set -o errexit
set -o nounset set -o nounset
rm -f './celerybeat.pid' rm -f './celerybeat.pid'
celery -A main.celery beat -l info exec python -m celery -A main.celery beat -l info

@ -13,6 +13,6 @@ until worker_ready; do
done done
>&2 echo 'Celery workers is available' >&2 echo 'Celery workers is available'
celery flower \ exec celery flower \
--app=main.celery \ --app=main.celery \
--broker="${CELERY_BROKER_URL}" --broker="${CELERY_BROKER_URL}"

@ -3,4 +3,11 @@
set -o errexit set -o errexit
set -o nounset set -o nounset
celery -A main.celery worker --loglevel=info # Use watchfiles during development
CELERY_WORKER_WATCH=${CELERY_WORKER_WATCH:-}
if [ ! -z $CELERY_WORKER_WATCH ]; then
watchfiles --filter python 'celery -A main.celery worker --loglevel=info'
else
exec python -m celery -A main.celery worker --loglevel=info
fi

@ -13,3 +13,11 @@ def divide(x, y):
time.sleep(5) time.sleep(5)
return x / y return x / y
@shared_task
def add(x, y):
import time
time.sleep(5)
return x + y

@ -6,3 +6,4 @@ psycopg2-binary==2.9.3
redis==4.3.4 redis==4.3.4
SQLAlchemy==1.4.40 SQLAlchemy==1.4.40
uvicorn[standard]==0.18.2 uvicorn[standard]==0.18.2
watchfiles==0.17.0

@ -107,7 +107,9 @@ vine==5.0.0
# celery # celery
# kombu # kombu
watchfiles==0.17.0 watchfiles==0.17.0
# via uvicorn # via
# -r requirements.in
# uvicorn
wcwidth==0.2.5 wcwidth==0.2.5
# via prompt-toolkit # via prompt-toolkit
websockets==10.3 websockets==10.3

Loading…
Cancel
Save