如何让django执行远程芹菜任务?似乎忽略settings.py中的代理URL
我有一个django应用程序,它试图调用芹菜任务,该任务最终将在一些远程主机上执行。任务代码库完全独立于django项目,因此我使用芹菜.execute.send_任务,并从post_delete模型信号调用它。代码看起来有点像这样:如何让django执行远程芹菜任务?似乎忽略settings.py中的代理URL,django,celery,Django,Celery,我有一个django应用程序,它试图调用芹菜任务,该任务最终将在一些远程主机上执行。任务代码库完全独立于django项目,因此我使用芹菜.execute.send_任务,并从post_delete模型信号调用它。代码看起来有点像这样: class MyModel(models.Model): @staticmethod def do_async_thing(sender, instance, **kwargs): celery.execute.send_task(
class MyModel(models.Model):
@staticmethod
def do_async_thing(sender, instance, **kwargs):
celery.execute.send_task("tasks.do_my_thing", args=[instance.name])
signals.post_delete.connect(MyModel.do_async_thing, sender=MyModel)
我正在使用最新的Django 1.6.1和Cellery 3.1.7,因此我知道我的Django项目中不需要任何额外的模块或应用程序,它就可以与Cellery对话。我已将my settings.py中的BROKER_URL设置为正确的URLamqp://user:password@主机/虚拟主机
当这个方法触发时,我得到一个连接被拒绝错误。芹菜代理上没有任何连接尝试的迹象-我猜它没有看到代理的URL配置,正在尝试连接到localhost
我该怎么做?send_task需要知道代理在哪里吗?因此我找到了答案,这与没有仔细阅读教程有关 具体地说,我已经准备好了正确的芹菜.py,我本以为应该加载这些设置,但我错过了django项目中对uu init_uu.py所做的必要更改,这并不是将所有内容都连接在一起 我的芹菜.py应该是:
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
app = Celery('mypoject')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
而_uinit__uuuuuuuuuy.py应该是:
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
所以我找到了答案,这与没有仔细阅读教程有关 具体地说,我已经准备好了正确的芹菜.py,我本以为应该加载这些设置,但我错过了django项目中对uu init_uu.py所做的必要更改,这并不是将所有内容都连接在一起 我的芹菜.py应该是:
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
app = Celery('mypoject')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
而_uinit__uuuuuuuuuy.py应该是:
from __future__ import absolute_import
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
只有一条注释:使用此设置,运行芹菜的命令必须是“芹菜-A myproject.celerry\u app worker”。我错过了.Cellery_应用程序,想知道为什么设置没有得到appliedjust一条评论:使用此设置,运行Cellery的命令必须是“Cellery-A myproject.Cellery_应用程序工作者”。我错过了.celery_应用程序,不知道为什么没有应用这些设置