Celery守护程序-如何配置它以从多个Flask应用程序运行多个任务? [英] Celery daemon - how to configure it to run multiple tasks from multiple Flask applications?

查看:130
本文介绍了Celery守护程序-如何配置它以从多个Flask应用程序运行多个任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个烧瓶应用程序 myapp_A ,该应用程序使用celery运行一些异步任务。而且我已经将celery配置为作为守护进程运行。这是服务脚本。

I have a flask app myapp_A that uses celery to run some asynchronous tasks. And I have configured celery to run as a daemon process. Here is the service script.

/ etc / default / celery:

# Name of nodes to start
CELERYD_NODES="w1"

# Absolute or relative path to the 'celery' command:
CELERY_BIN="/var/www/myapp_A.com/public_html/venv/bin/celery"

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

# Where to chdir at start.
CELERYD_CHDIR="/var/www/myapp_A.com/public_html/"

# 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"
CELERYD_LOG_LEVEL="INFO"

# Workers should run as an unprivileged user.
CELERYD_USER="myuser"
CELERYD_GROUP="www-data"

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

/etc/init.d/celeryd:

/etc/init.d/celeryd:

Celery从这里

现在我有另一个Flask应用程序 myapp_B 也需要芹菜来运行任务。

Now I have another Flask app myapp_B that requires celery to run tasks as well.


  • 如何为此配置?

  • 我应该以其他名称创建另一个守护进程吗?

  • 如何为多个芹菜进程配置消息代理(RabbitMQ)?

推荐答案

您可以使用单个守护进程来处理这两个应用程序。
一种方法是对不同的应用程序使用不同的队列名
这是我正在使用的配置

You can use a single daemon process to work with both applications. one way is to to use different queue names for different applications Here is the config I'm using

celery worker -A init_celery --quiet --loglevel=$WORKER_LOG_LEVEL --concurrency=4 --queues=que1,que2

然后在每个应用程序中指定队列名称。使用

Then specify the queue name in each application. using

CELERY_DEFAULT_QUEUE = 'que1'

这篇关于Celery守护程序-如何配置它以从多个Flask应用程序运行多个任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆