docker-compose和优雅的Celery关闭 [英] docker-compose and graceful Celery shutdown
问题描述
我一直想知道并寻找解决方案,但没有找到任何解决方法。
I've been wondering about and searching for solutions for this and I didn't find any.
我正在用docker-建造的容器中运行Celery-撰写。我的容器的配置如下:
I'm running Celery in a container built with docker-compose. My container is configured like this:
celery:
build: .
container_name: cl01
env_file: ./config/variables.env
entrypoint:
- /celery-entrypoint.sh
volumes:
- ./django:/django
depends_on:
- web
- db
- redis
stop_grace_period: 1m
我的入口点脚本如下:
#!/bin/sh
# Wait for django
sleep 10
su -m dockeruser -c "celery -A myapp worker -l INFO"
现在,如果我运行 docker-compose stop
,我想进行一次温暖(优美)的关机,给Celery提供1分钟( stop_grace_period
)来完成已经开始的任务。但是 docker-compose stop
似乎立即杀死了Celery。芹菜还应该记录它被要求正常关闭的信息,但是除了突然停止我的任务日志外,我什么都看不到。
Now, if I run docker-compose stop
, I would like to have a warm (graceful) shutdown, giving Celery the provided 1 minute (stop_grace_period
) to finish already started tasks. However docker-compose stop
seems to kill Celery straight away. Celery should also log that it is asked to shut down gracefully, but I don't see anything but an abrupt stop to my task logs.
我在做什么错了或我需要进行哪些更改才能使Celery正常关闭?
What am I doing wrong or what do I need to change to make Celery shut down gracefully?
编辑:
下面建议的有关提供-timeout
的 docker-compose stop
参数不能解决我的问题。
edit:
Suggested answer below about providing the --timeout
parameter to docker-compose stop
does not solve my issue.
推荐答案
您需要用 exec
标记 celery
进程,这样celery进程将具有相同的ID
You need to mark celery
process with exec
, this way celery process will have the same ID as docker command and docker will be able to send a SIGTERM signal to it and gracefully close celery process.
# should be the last command in script
exec celery -A myapp worker -l INFO
这篇关于docker-compose和优雅的Celery关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!