Celery - How to send task from remote machine?

旧巷老猫 提交于 2019-12-02 19:09:43

This may be a way: Creating a Celery object and using send_task from that object, the object can have the configuration to find the broker.

from celery import Celery
celery = Celery()
celery.config_from_object('celeryconfig')
celery.send_task('tasks.add', (2,2))

celeryconfig is a file containing the celery configuration, there are other ways set config on the celery object.

There are several ways to define routing rules, the most general of which is the custom router object. In all cases, the caller just provides a routing_key parameter in send_task, delay or apply_async and the router determines which queue to send the task into.

on the remote machine, start up celery with the broker_url pointing to the machine you want to run the tasks on. Then just submit the tasks (if you have specific queues to submit to, then add the appropriate routing keys).

D0neZer0

What you found was right.

from celery.execute import send_task

send_task('tasks.add')

If any args needed

send_task('tasks.add', kwargs={'a': 1, 'b': 2})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!