如何将芹菜任务注册到特定工人? [英] How to register Celery task to specific worker?

查看:69
本文介绍了如何将芹菜任务注册到特定工人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python/Django开发Web应用程序,并且有一些任务正在芹菜中运行.

我必须一次运行一个任务A,所以我使用--concurrency = 1创建了工作程序,并使用以下命令将任务A路由到该工作程序.

  celery-项目工作者-Q A -c 1 -l INFO 

此工作程序处理任务A并将其他任务路由到默认队列后,一切工作正常.

但是,当我使用 inspect 命令获取工作人员的注册任务时,上述工作人员会返回所有任务.这是绝对正确的,因为当我开始工作时,它会将项目的所有任务显示为已注册任务,但仅处理任务A.

以下是我启动工作程序时的输出.

  $ celery-项目工作者-Q A -c 1 -l INFO-------------- celery @ pet_sms v4.0.2(潜在呼叫)---- **** -------- * *** *-Linux-4.8.10-040810-generic-x86_64-with-Ubuntu-16.04-xenial 2018-04-26 14:11:49-*-**** ----** ---------- [config]-** ----------.>应用:proj:0x7f298a10d208-** ----------.>传输:redis://localhost:6379/0-** ----------.>结果:禁用://-*** --- * ---.>并发:1(prefork)-******* ----.>任务事件:OFF(启用-E监视此工作程序中的任务)--- ***** ------------------- [队列].交换= A(直接)键= A[任务].task_one.task_two.task_three.一种.task_four.task_five 

有什么方法可以将特定任务注册给芹菜工人吗?

解决方案

请注意工作日志中的以下两个部分.

  [队列].交换= A(直接)键= A[任务].task_one.task_two.task_three.一种.task_four.task_five 

第一部分 [队列] 显示您的工人消耗的队列.

它显示 A,exchange = A(direct),key = A ,指示此工作程序仅使用队列 A 中的任务.正是您想要的.并且之所以能达到这种效果,是因为在您通过命令 $ celery -A proj worker -QA -c 1 -l INFO 启动工作程序时指定了 -QA .

第二部分 [任务] 显示此应用的所有已注册任务.

尽管其他任务(例如 task_one task_five )都已注册,因为这些任务没有进入队列 A ,因此此工作程序不会消耗任务 task_one task_five .

I am developing web application in Python/Django, and I have several tasks which are running in celery.

I have to run task A one at a time so I have created worker with --concurrency=1 and routed task A to that worker using following command.

celery -A proj worker -Q A -c 1 -l INFO

Everything is working fine as this worker handle task A and other tasks are routed to default queue.

But, above worker return all task when I use inspect command to get registered task for worker. That is absolutely true because when I start worker, it displays all tasks of projects as registered task but handle only task A.

Following is the output of worker when I start it.

$ celery -A proj worker -Q A -c 1 -l INFO

 -------------- celery@pet_sms v4.0.2 (latentcall)
---- **** ----- 
--- * ***  * -- Linux-4.8.10-040810-generic-x86_64-with-Ubuntu-16.04-xenial 2018-04-26 14:11:49
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .> app:         proj:0x7f298a10d208
- ** ---------- .> transport:   redis://localhost:6379/0
- ** ---------- .> results:     disabled://
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> A exchange=A(direct) key=A


[tasks]
  . task_one
  . task_two
  . task_three
  . A
  . task_four
  . task_five

Is there any way to register specific task to the worker in celery?

解决方案

Notice following two parts in your worker log.

[queues]
  .> A exchange=A(direct) key=A

[tasks]
  . task_one
  . task_two
  . task_three
  . A
  . task_four
  . task_five

The first part [queues] shows the queues your worker consumes.

And it shows A, exchange=A(direct), key=A, indicating this worker only consumes tasks that are from the queue A. Which is exactly what you want. And you were achieving this effect because you specified -Q A when you started the worker by the command $ celery -A proj worker -Q A -c 1 -l INFO.

The second part [tasks] shows all the registered tasks of this app.

Though other tasks such as task_one task_five are all registered, since these tasks do not go into queue A, therefore this worker does not consume the tasks task_one task_five.

这篇关于如何将芹菜任务注册到特定工人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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