gpt4 book ai didi

python - Celery:自动启动 Worker(启动时)

转载 作者:行者123 更新时间:2023-11-28 22:47:11 24 4
gpt4 key购买 nike

我在 /var/tasks/tasks.py 中定义了任务(对于 Celery)。

我在 /var/tasks/venv 有一个 virtualenv,应该用来运行 /var/tasks/tasks.py

我可以手动启动一个worker来处理这样的任务:

cd /var/tasks
. venv/bin/activate
celery worker -A tasks -Q queue_1

现在,我想将其守护进程。

我从 GitHub 复制了 init.d 脚本并在 /etc/default/celeryd 中使用以下配置文件:

# name(s) of nodes to start
CELERYD_NODES="worker1"

# absolute or relative path to celery binary
CELERY_BIN="/var/tasks/venv/bin/celery"

# app instance
CELERY_APP="tasks"

# change to directory on upstart
CELERYD_CHDIR="/var/tasks"

# options
CELERYD_OPTS="-Q queue_1 --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"

# unprivileged user/group
CELERYD_USER="celery"
CELERYD_GROUP="celery"

# create pid and log directories, if missing
CELERY_CREATE_DIRS=1

当我启动服务时(通过 init.d 脚本),它说:

celery init v10.1.
Using config script: /etc/default/celeryd

但是,它不处理队列中的任何任务,日志文件中也没有任何内容。

我做错了什么?

最佳答案

Supervisor可能是一个不错的选择,但如果您想使用 Celery Init.d 脚本,将建议您从他们的 Github 源代码中复制它。

sudo vim /etc/init.d/celeryd

https://github.com/celery/celery/blob/master/extra/generic-init.d/celeryd复制代码在文件中。参见 daemonizing tutorial了解详情。

sudo chmod 755 /etc/init.d/celeryd
sudo chown root:root /etc/init.d/celeryd
sudo nano /etc/default/celeryd

复制粘贴下面的配置并进行相应的更改

#Where your Celery is present
CELERY_BIN="/home/shivam/Desktop/deploy/bin/celery"

# App instance to use
CELERY_APP="app.celery"

# Where to chdir at start
CELERYD_CHDIR="/home/shivam/Desktop/Project/demo/"

# 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%I.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="shivam"
CELERYD_GROUP="shivam"

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

保存并退出

sudo /etc/init.d/celeryd start
sudo /etc/init.d/celeryd status

这将在启动时自动启动 Celery

sudo update-rc.d celeryd defaults

关于python - Celery:自动启动 Worker(启动时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26619845/

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