向所有工人广播任务:redis +芹菜

时间:2017-05-10 16:27:54

标签: python redis celery broadcast

tasks.py

    from celery import Celery

app = Celery('tasks',
             broker='redis://localhost',
             backend='redis://localhost',
             include=['tasks'])

app.conf.broker_url = 'redis://localhost:6379/0'
# Optional configuration, see the application user guide.
app.conf.update(
    result_expires=3600,
)
@app.task
def add(x, y):
    return x + y

main.py

from tasks import add


    if __name__ == '__main__':
        from celery import Celery
        app = Celery('tasks', backend='redis://localhost', broker='redis:localhost//')
        result = add.delay(4, 4)
        result.ready()
        value = result.get(timeout=10)
        print(value)

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

1 个答案:

答案 0 :(得分:0)

例如:

import tasks
if __name__ == '__main__':
    tasks.app.do_something.apply_async(['222'], queue='broadcast_tasks')