Skip to content

Commit b7dd8b9

Browse files
chore: Restart celery worker on source changes (ietf-tools#5749)
* chore: Restart celery worker on Python source change * chore: Debounce celery restarts, only watch ietf dir
1 parent 2ca4f7b commit b7dd8b9

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

dev/celery/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ COPY requirements.txt /tmp/pip-tmp/
1717
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt
1818
RUN rm -rf /tmp/pip-tmp
1919

20-
ENTRYPOINT [ "/docker-init.sh" ]
20+
# Add watchmedo utility for dev containers
21+
RUN pip3 --disable-pip-version-check --no-cache-dir install watchdog[watchmedo]
22+
23+
ENTRYPOINT [ "/docker-init.sh" ]

dev/celery/docker-init.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
# DEBUG_TERM_TIMING - if non-empty, writes debug messages during shutdown after a TERM signal
1717
#
18+
# DEV_MODE - if non-empty, restart celery worker on Python file change
19+
#
1820
WORKSPACEDIR="/workspace"
1921
CELERY_ROLE="${CELERY_ROLE:-worker}"
2022

@@ -85,6 +87,18 @@ fi
8587

8688
trap 'trap "" TERM; cleanup' TERM
8789
# start celery in the background so we can trap the TERM signal
88-
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
89-
celery_pid=$!
90+
if [[ -n "${DEV_MODE}" ]]; then
91+
watchmedo auto-restart \
92+
--patterns '*.py' \
93+
--directory 'ietf' \
94+
--recursive \
95+
--debounce-interval 5 \
96+
-- \
97+
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
98+
celery_pid=$!
99+
else
100+
celery --app="${CELERY_APP:-ietf}" "${CELERY_OPTS[@]}" "$@" &
101+
celery_pid=$!
102+
fi
103+
90104
wait "${celery_pid}"

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ services:
7474
CELERY_APP: ietf
7575
CELERY_ROLE: worker
7676
UPDATE_REQUIREMENTS_FROM: requirements.txt
77+
DEV_MODE: yes
7778
command:
7879
- '--loglevel=INFO'
7980
depends_on:

0 commit comments

Comments
 (0)