即使连接成功也无法触发芹菜任务

时间:2018-07-16 21:00:26

标签: django rabbitmq celery

我有2个ec2实例:1个已安装django celery和我的应用程序,另外2个已安装RabbitMQ。

我最近从连接并正常工作的芹菜和redis切换到了

在芹菜侧,日志看起来像是与消息联系在一起的:

Connected to amqp://celeryuser:**@myip/celeryvhost
mingle: searching for neighbors
mingle: all alone
worker1@myhost ready.

在Rabbit服务器上,通过以下日志消息连接也看起来不错:

> accepting AMQP connection <0.507.0> (internalip:45564 ->
> anotherinternalip:5672) connection <0.507.0> (internalip:45564 ->
> anotherinternalip:5672): user 'celeryuser' authenticated and granted
> access to vhost 'celeryvhost'

我的celery.py连接信息如下:

app = Celery('myapp',
                 broker='amqp://celeryuser:mypass@mypublicip:5672/celeryvhost',
                 backend='amqp://celeryuser:mypass@mypublicip:5672/celeryvhost',
                 include=['social.tasks']
                 ) 

我通过以下方式启动任务

new_comment_notification.apply_async((1), queue='lopri', countdown=5)

并且:

from mysite.celery import app
from django.conf import settings
from django.core.mail import send_mail

@app.task
def new_comment_notification(post_id):
    print(post_id)


    send_mail(
        'New Comment',
        'New Comment',
        settings.DEFAULT_FROM_EMAIL,
        ['my@email.com'],
        fail_silently=False,
    )

我监视日志,并且在触发new_comment_notification时它们不会移动。没有迹象表明已经生成了任务,就像我以前在redis实现中能够看到的那样。

我尝试通过手动启动celery来解决问题: celery -test_celery工作者--loglevel = info

我的test_celery看起来像:

from celery import Celery
import time
app = Celery('test_celery',
             broker= 'amqp://celeryuser:mypass@publiccip:5672/celeryvhost',
             )

@app.task
def add(x, y):
    time.sleep(2)
    print('calculating something aaewsome --------------------')
    return x + y

当我用以下命令调用它时,这没问题

 add.delay(2, 2)

没有错误,并且在我一个接一个地调用任务时日志保持不变。

我在做什么错?

0 个答案:

没有答案