【问题标题】:Broadcast task to all workers: redis+celery向所有worker广播任务:redis+celery
【发布时间】:2017-05-10 16:27:54
【问题描述】:

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(代理和后端)和 celery 向所有工作人员广播任务,但我没有实现,你能帮帮我吗?

【问题讨论】:

  • 对不起,我不明白你的评论,请你说得更具体些
  • 您在tasks.py 中已经有一个app,并在__main__ 中创建一个新的。
  • 是的,这是真的,我不需要 main.py 中的行:app = Celery('tasks', backend='redis://localhost', broker='redis:localhost// ')
  • 你知道,我怎样才能向所有工人广播任务?
  • 你试过tasks.app,因为这个app表现不同。

标签: python redis celery broadcast


【解决方案1】:

例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-17
    • 2017-10-11
    • 2018-08-06
    • 2012-06-06
    • 2017-10-23
    • 2023-03-07
    • 2021-01-24
    • 2012-01-22
    相关资源
    最近更新 更多