1
所有工人我嘗試: main.py廣播的任務是用的Redis和芹菜
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(broker和後端)和芹菜的工人,但是我沒有達到,你能幫助我嗎?
謝謝,我會跟着這個問題 –