我试着: 的 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(经纪人和后端)和芹菜向所有工作人员播放任务,但我没有实现,你能帮助我吗?