我一直试图用Celery,RabbitMQ,Django进行一些测试..
问题是,一旦我产生了一个工人,我使用django来发送一个任务,这要归功于工人收到的.delay(),但从工作中看,工人找不到那个名字的任务执行。奇怪的是,因为具有完全相同名称的任务是工作者应该能够执行的任务列表。
这是:
- > settings.py
BROKER_HOST = "127.0.0.1" #IP address of the server running RabbitMQ and Celery
BROKER_PORT = 5672
BROKER_URL = 'amqp://'
CELERY_IMPORTS = ('notify')
CELERY_IGNORE_RESULT = False
CELERY_RESULT_BACKEND = "amqp"
CELERY_IMPORTS = ("notify")
- > __init__.py
(在通知模块下)
import celery
from celery import app as celery_app
from notify.user.tasks import send_email
- > tasks.py
(在通知模块下)
import os
from celery import Celery, task
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.config_from_object('app.settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS, force=False)
@task()
def send_email(recepient, title, subject):
print('sending email')
以下是我如何在我的项目的根部产生我的工作人员:
celery worker -n worker_one -l debug -A notify
以下是当工作人员收到我发送的任务通知时得到的错误:
The full contents of the message body was:
'[["Guillaume", "One title", "This is my subject"], {}, {"chain": null, "callbacks": null, "errbacks": null, "chord": null}]' (123b)
Traceback (most recent call last):
File "/Users/guillaumeboufflers/.pyenv/versions/smartbase/lib/python3.5/site-packages/celery/worker/consumer/consumer.py", line 561, in on_task_received
strategy = strategies[type_]
KeyError: 'notify.user.tasks.send_email'
这很奇怪,因为......
[tasks]
. celery.accumulate
. celery.backend_cleanup
. celery.chain
. celery.chord
. celery.chord_unlock
. celery.chunks
. celery.group
. celery.map
. celery.starmap
. notify.user.tasks.send_email
谢谢大家的帮助......