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



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 (经纪人和后端(和芹菜的工人广播任务,但我没有实现,你能帮我吗?

例如:

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

最新更新