向所有有redis和芹菜的工人广播任务

时间:2017-05-16 10:37:31

标签: python redis celery broadcast

我试着: main.py

import tasks
if __name__ == '__main__':
    result = tasks.add.apply_async(([4, 4]), queue='broadcast_tasks')
    result.ready()
    value = result.get()
    print(value)

tasks.py

from celery import Celery
from kombu.common import Broadcast
app = Celery('tasks',
             broker='redis://localhost:6379/0',
             backend='redis://localhost:6379/1',
             include=['tasks'])
app.conf.update(
    result_expires=3600,
)
task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
timezone = 'UTC'

app.conf.task_queues = (Broadcast('broadcast_tasks'),)
app.conf.task_routes = {'tasks.add': {'queue': 'broadcast_tasks'}}


@app.task
def add(x, y):
    return x + y

我想用redis(经纪人和后端)和芹菜向所有工作人员播放任务,但我没有实现,你能帮助我吗?

1 个答案:

答案 0 :(得分:1)

芹菜团队正在合并相应的问题: https://github.com/celery/celery/pull/3934

这应该在下一个版本中提供(我希望)。