Celery-如何从远程计算机发送任务? [英] Celery - How to send task from remote machine?

查看:108
本文介绍了Celery-如何从远程计算机发送任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一台运行芹菜工作者和Redis队列的服务器。这些任务是在该服务器上定义的。

我需要能够从远程计算机调用这些任务。

我知道它是使用 send_task完成的但我仍然不知道如何?如何告诉 send_task 队列在哪里?我在哪里传递连接参数(或任何需要的参数)?我一直在寻找时间,所有我能找到的是:

We have a server running celery workers and a Redis queue. The tasks are defined on that server.
I need to be able to call these tasks from a remote machine.
I know that it is done using send_task but I still haven't figured out HOW? How do I tell send_task where the queue is? Where do I pass connection params (or whatever needed)? I've been looking for hours and all I can find is this:

from celery.execute import send_task
send_task('tasks.add')

嗯,这意味着我需要芹菜也在我的呼叫机器上。但是我还需要设置什么?

Well, that means that I need celery on my calling machine as well. But what else do I need to set up?

推荐答案

这可能是一种方法:
创建一个Celery对象,然后使用该对象的send_task,该对象可以进行配置以查找代理。

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是一个包含celery配置的文件,还有其他方法可以在celery对象上设置config。

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

这篇关于Celery-如何从远程计算机发送任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆