chore: Restart celery worker on source changes (#5749)

* chore: Restart celery worker on Python source change

* chore: Debounce celery restarts, only watch ietf dir
This commit is contained in:
Jennifer Richards 2023-06-08 16:13:46 -03:00 committed by GitHub
parent 2ca4f7beaf
commit b7dd8b9b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View file

@ -17,4 +17,7 @@ COPY requirements.txt /tmp/pip-tmp/
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt
RUN rm -rf /tmp/pip-tmp
ENTRYPOINT [ "/docker-init.sh" ]
# Add watchmedo utility for dev containers
RUN pip3 --disable-pip-version-check --no-cache-dir install watchdog[watchmedo]
ENTRYPOINT [ "/docker-init.sh" ]

View file

@ -15,6 +15,8 @@
#
# DEBUG_TERM_TIMING - if non-empty, writes debug messages during shutdown after a TERM signal
#
# DEV_MODE - if non-empty, restart celery worker on Python file change
#
WORKSPACEDIR="/workspace"
CELERY_ROLE="${CELERY_ROLE:-worker}"
@ -85,6 +87,18 @@ fi
trap 'trap "" TERM; cleanup' TERM
# start celery in the background so we can trap the TERM signal
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
celery_pid=$!
if [[ -n "${DEV_MODE}" ]]; then
watchmedo auto-restart \
--patterns '*.py' \
--directory 'ietf' \
--recursive \
--debounce-interval 5 \
-- \
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
celery_pid=$!
else
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
celery_pid=$!
fi
wait "${celery_pid}"

View file

@ -74,6 +74,7 @@ services:
CELERY_APP: ietf
CELERY_ROLE: worker
UPDATE_REQUIREMENTS_FROM: requirements.txt
DEV_MODE: yes
command:
- '--loglevel=INFO'
depends_on: