gpt4 book ai didi

python - celery 运行作为守护进程停止

转载 作者:太空宇宙 更新时间:2023-11-04 09:25:22 27 4
gpt4 key购买 nike

我已经在 centos linux 服务器上使用 redis 安装了 celery。

我使用以下命令启动一个 celery worker:

celery multi start worker1 -A proj -Q lopri,lopri2 -l info --pidfile="$HOME/run/celery/%n.pid" --logfile="$HOME/log/celery/%n.log"

问题是几个小时后,worker不再响应创建任务。我必须重新启动 worker 才能再次处理任务。

这是位于/etc/default/celeryd 的 celery 设置文件:

# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS (see `celery multi --help` for examples):
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"

# App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app"

#django settings
#export DJANGO_SETTINGS_MODULE="settings"

# Where to chdir at start.
CELERYD_CHDIR="/var/www/html/proj/"

# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"

# %N will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%N.log"
CELERYD_PID_FILE="/var/run/celery/%N.pid"

# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists, e.g. nobody).
CELERYD_USER="ec2-user"
CELERYD_GROUP="ec2-user"

# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1

一个问题可能是正在发生的事情的线索是我必须从项目文件夹运行“开始”命令否则我会收到错误:

ImportError: No module named proj

CELERYD_CHDIR 设置不应该解决这个问题吗?这是否意味着我的启动命令没有使用这个 celery 默认设置文件?

感谢您提供的任何信息。

最佳答案

如果您通过命令行运行 celery,您的设置文件几乎毫无用处。我的意思是,它们没有被应用,这就是为什么您会收到一条错误消息,提示您的项目无法导入。

这是将 celery 作为守护进程运行的脚本: https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd

如您所见:https://github.com/celery/celery/blob/3.1/extra/generic-init.d/celeryd#L56这是脚本导入您的设置的地方。

我不太清楚为什么你的 celeryd 在几个小时后停止工作,但这表明你并没有真正作为守护进程运行。也许使用设置设置属性 init.d 脚本可以解决这个问题,但我对此表示怀疑。

关于python - celery 运行作为守护进程停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37078186/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com