在同一台服务器上运行celery的多个实例 [英] Running multiple instances of celery on the same server

查看:47
本文介绍了在同一台服务器上运行celery的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一台计算机上运行两个celery实例.一个用于我的应用程序的"A"版本,另一个用于"B"版本.

I want to run two instances of celery on the same machine. One is for an 'A' version of my application, the other is for the 'B' version.

我有两个实例,我是这样开始的:

I have two instances, which I start like this:

(env1)/home/me/firstapp$ celery -A app.tasks worker --config celeryconfig
(env2)/home/me/secondapp$ celery -A app.tasks worker -n Carrot --config celeryconfig

在每个应用程序的task.py中,我创建一个celery实例,如下所示:

In tasks.py in each application, I create a celery instance like this:

 celery = Celery('tasks', backend='amqp', broker='amqp://guest@127.0.0..1.5672//')
 @celery.task
 def run_a_task():
     do_stuff()

在env2的task.py中,如何指定要使用secondapp(名为Carrot)中的第二个celery实例,而不是firstapp中的第一个芹菜实例?我怀疑我需要在第一行的芹菜的构造函数中更改一些内容,但我不知道要添加什么.

In env2's task.py, how can I specify that I want to use the second celery instance from secondapp(named Carrot), rather than the first one from firstapp? I suspect I need to change something in the constructor for celery on the first line, but I don't know what to add.

推荐答案

我通过使用虚拟芹菜主机解决了这个问题.

I solved this by using a virtual host for celery.

rabbitmq服务器一旦运行,我将发出以下命令:

Once the rabbitmq server is running I issue these commands:

rabbitmqctl add_user user password
rabbitmqctl add_vhost app2
rabbitmqctl set_permissions -p app2 user ".*" ".*" ".*"

然后我以以下内容开始芹菜:

Then I start celery with:

celery -A tasks worker --broker=amqp://user:password@localhost/app2

在执行任务时,我像这样初始化celery对象:

With my task, I initialize the celery object like this:

celery = Celery('tasks', backend='amqp', broker='amqp://user:password@localhost:5672/app2

这篇关于在同一台服务器上运行celery的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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