在Celery中,我将消息发布到具有指定优先级的队列中,但是这些消息没有显示在Redis后端的celery
列表中或我的花朵监视中。
我希望能够在任何给定时间内查看队列中有多少条消息,以便查看是否需要更多工作人员。
我正在使用以下代码呼叫消息:
args = ("2eb89997-7e77-44ee-8bf5-077e5083b7e8", { "body": "hello-world 1", "json": { "time": 1 }, "source": "reddit", "link": "a", "username" : "a"},)
app.send_task("main.tasks.save_message_mid_priority", args=args, priority=1)
如果我呼叫的消息没有优先权,则显示在默认的celery
队列中,我可以对其进行监视。如果我通过了考试,那么我不会通过。
这是我的celery.app
from __future__ import absolute_import, unicode_literals
from django.conf import settings
import os
from celery import Celery
from kombu import Queue, Exchange
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '***.settings')
app = Celery('***', broker=settings.REDIS_URL)
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
app.conf.broker_transport_options = {
'priority_steps': list(range(4)),
}
app.conf.task_default_priority = 3
app.conf.task_queue_max_priority = 3
app.conf.task_soft_time_limit = 60
app.conf.task_acks_late = True
app.conf.worker_prefetch_multiplier = 1
app.conf.task_ignore_result = True
我的任务定义如下:
@app.task(bind=True, priority=0)
def save_message_high_priority(self, campaign_id, message):
l.info("save_message: %s %s", campaign_id, self.priority)
return save_message(campaign_id, message)
@app.task(bind=True, priority=1)
def save_message_mid_priority(self, campaign_id, message):
l.info("save_message: %s %s", campaign_id, self.priority)
return save_message(campaign_id, message)
@app.task(bind=True, priority=3)
def save_message_low_priority(self, campaign_id, message):
l.info("save_message: %s %s", campaign_id, self.priority)
return save_message(campaign_id, message)