-
Notifications
You must be signed in to change notification settings - Fork 40
Fix container lifecycle: signals, worker queues, healthcheck #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,19 @@ FROM base AS web | |
| HEALTHCHECK --interval=15s --timeout=15s --start-period=15s --retries=3 \ | ||
| CMD wget --quiet --tries=1 --spider http://localhost:8000/api/v1/healthchecks/ | ||
|
|
||
| CMD ["sh", "-c", "python manage.py migrate && uwsgi --master --http=:8000 --venv=/code/.venv/ --wsgi=app.wsgi --workers=2 --threads=2 --harakiri=25 --max-requests=1000 --log-x-forwarded-for --logformat '%(addr) - - [%(ltime)] \"%(method) %(uri) %(proto)\" %(status) %(size) \"%(referer)\" \"%(uagent)\"'"] | ||
| CMD ["sh", "-c", "python manage.py migrate \ | ||
| && exec uwsgi \ | ||
| --master \ | ||
| --die-on-term \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. без этого uwsgi релоадит воркеров, а не останавливается |
||
| --http=:8000 \ | ||
| --venv=/code/.venv/ \ | ||
| --wsgi=app.wsgi \ | ||
| --workers=2 \ | ||
| --threads=2 \ | ||
| --harakiri=25 \ | ||
| --max-requests=1000 \ | ||
| --log-x-forwarded-for \ | ||
| --logformat '%(addr) - - [%(ltime)] \"%(method) %(uri) %(proto)\" %(status) %(size) \"%(referer)\" \"%(uagent)\"'"] | ||
|
|
||
| # | ||
| # worker image | ||
|
|
@@ -81,9 +93,17 @@ FROM base AS worker | |
|
|
||
| ENV _CELERY_APP=app.celery | ||
| HEALTHCHECK --interval=15s --timeout=15s --start-period=5s --retries=3 \ | ||
| CMD celery --app=${_CELERY_APP} inspect ping --destination=$QUEUE@$HOSTNAME | ||
|
|
||
| CMD ["sh", "-c", "celery --app=${_CELERY_APP} worker --concurrency=${CONCURRENCY:-2} --hostname=celery@%h --max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50} --time-limit=${TIME_LIMIT:-900} --soft-time-limit=${SOFT_TIME_LIMIT:-45}"] | ||
| CMD celery --app=${_CELERY_APP} inspect ping --destination=${WORKER_NAME:-celery}@$HOSTNAME | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут поправили healthcheck у воркеров: было |
||
|
|
||
| CMD ["sh", "-c", "exec celery \ | ||
| --app=${_CELERY_APP} \ | ||
| worker \ | ||
| --queues=${QUEUES:-celery} \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Добавил флаг с очередями. Его не было, и чтобы запустить второй воркер на другой очереди, приходилось переписывать CMD в Dockerfile. Теперь очередь задаётся через |
||
| --hostname=${WORKER_NAME:-celery}@%h \ | ||
| --concurrency=${CONCURRENCY:-2} \ | ||
| --max-tasks-per-child=${MAX_REQUESTS_PER_CHILD:-50} \ | ||
| --time-limit=${TIME_LIMIT:-900} \ | ||
| --soft-time-limit=${SOFT_TIME_LIMIT:-45}"] | ||
|
|
||
| # | ||
| # scheduler image | ||
|
|
@@ -98,4 +118,8 @@ VOLUME ${_SCHEDULER_DB_PATH} | |
|
|
||
| ENV _CELERY_APP=app.celery | ||
| HEALTHCHECK NONE | ||
| CMD ["sh", "-c", "celery --app=${_CELERY_APP} beat --pidfile=/tmp/celerybeat.pid --schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db"] | ||
| CMD ["sh", "-c", "exec celery \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь и везде переписал аргументы в столбик: так понятнее дифы и блеймы смотреть, что к чему относиться и комментить в PR :) |
||
| --app=${_CELERY_APP} \ | ||
| beat \ | ||
| --pidfile=/tmp/celerybeat.pid \ | ||
| --schedule=${_SCHEDULER_DB_PATH}/celerybeat-schedule.db"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь и в других местах:
execубираетshиз цепочки tini → sh → приложение.Почему нужно: dash (shell-оболочка в контейнере) не передаёт SIGTERM дальше, а выходит сам, и uwsgi с celery про остановку не узнают. То есть когда добавили tini, контейнеры стали быстро завершаться, но по факту убивались, т.к. сигнал для корректной остановки не доходил до приложения.