我需要使用 python 和 Celery 获取工作队列大小。该代码运行良好,但结果仅限于 10 项。有什么方法可以获取排队任务的完整列表吗?我收到了 100 多件商品,但只有 10 件被退回
res = i.reserved() # Names of tasks reserved by the worker
reserved_count = len(res[queue_name])
完整代码:
app = Celery('myapp', broker='redis://redis:6379/0')
# Tist of queue names to inspect
queue_names = ['[email protected]', '[email protected]']
queue_info = {}
# Iterate through the queue names
for queue_name in queue_names:
i = app.control.inspect([queue_name])
a = i.active() # Names of tasks currently being executed by the worker
active_count = len(a[queue_name])
res = i.reserved() # Names of tasks reserved by the worker
reserved_count = len(res[queue_name])
pretty_queue_name = queue_name.replace('celery@worker.', '')
queue_info[pretty_queue_name] = {
'active': active_count,
'reserved': reserved_count,
'total': active_count + reserved_count
}
return queue_info
执行此操作的 bash 命令是:
celery -A <your_celery_app> worker -l info -c 100 -Q <your_queue_name>