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(经纪人和后端)和芹菜向所有工作人员播放任务,但我没有实现,你能帮助我吗?
答案 0 :(得分:0)
例如:
import tasks
if __name__ == '__main__':
tasks.app.do_something.apply_async(['222'], queue='broadcast_tasks')