如何使用 Redis 作为代理清除 celery 队列中的任务

Pyt*_*ast 8 python celery

第1部分

我已经阅读并尝试了各种 SO 线程来使用 Redis 清除 celery 任务,但它们都不起作用。请让我知道如何使用 Redis 作为代理清除 celery 中的任务。

第2部分

另外,我有多个队列。我可以在项目目录中运行它,但是在妖魔化时,工作人员不接任务。我仍然需要手动启动芹菜工人。我怎样才能消除它?

这是我的celerd conf。

# Name of nodes to start, here we have a single node
CELERYD_NODES="w1 w2 w3 w4"


CELERY_BIN="/usr/local/bin/celery"

# Where to chdir at start.
CELERYD_CHDIR="/var/www/fractal/parser-quicklook/"

# Python interpreter from environment, if using virtualenv
#ENV_PYTHON="/somewhere/.virtualenvs/MyProject/bin/python"

# How to call "manage.py celeryd_multi"
#CELERYD_MULTI="/usr/local/bin/celeryd-multi"

# How to call "manage.py celeryctl"
#CELERYCTL="/usr/local/bin/celeryctl"

#CELERYBEAT="/usr/local/bin/celerybeat"

# Extra arguments to celeryd
CELERYD_OPTS="--time-limit=300 --concurrency=8  -Q BBC,BGR,FASTCOMPANY,Firstpost,Guardian,IBNLIVE,LIVEMINT,Mashable,NDTV,Pandodaily,Reuters,TNW,TheHindu,ZEENEWS "

# Name of the celery config module, don't change this.
CELERY_CONFIG_MODULE="celeryconfig"

# %n will be replaced with 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.
#CELERYD_USER="nobody"
#CELERYD_GROUP="nobody"

# Set any other env vars here too!
PROJET_ENV="PRODUCTION"

# Name of the projects settings module.
# in this case is just settings and not the full path because it will change the dir to
# the project folder first.
CELERY_CREATE_DIRS=1
Run Code Online (Sandbox Code Playgroud)

Celeryconfig 已在第 1 部分中提供。

这是我的项目目录结构。

project
|-- main.py
|-- project
|   |-- celeryconfig.py
|   |-- __init__.py
|-- tasks.py
Run Code Online (Sandbox Code Playgroud)

我怎么能用队列妖魔化?我也提供了队列CELERYD_OPTS

有没有一种方法可以动态妖魔化芹菜中的队列数量?例如:- 我们必须CELERY_CREATE_MISSING_QUEUES = True创建丢失的队列。有没有类似于守护芹菜队列的东西?

Cap*_*iel 10

celery purge应该足以清理redis中的队列。但是,您的工作人员将拥有自己的保留任务,并且会在您停止工作人员时将它们发送回队列。所以,首先,停止所有工人。然后运行celery purge


nbe*_*hat 8

如果您有多个队列,celery purge将清除默认队列。您可以指定要清除的队列,如下所示:

celery purge -A proj -Q queue1,queue2
Run Code Online (Sandbox Code Playgroud)