My settings.py
CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml', 'pickle', 'application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = 'djcelery.backends.cache:CacheBackend'
celery.py 代码
from __future__ import absolute_import
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webapp.settings')
from django.conf import settings
app = Celery('webapp')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
tasks.py 代码
from __future__ import absolute_import
from celery.utils.log import get_task_logger
from celery import shared_task
import datetime
logger = get_task_logger(__name__)
@shared_task
def sample_code():
logger.info("Run time:" + str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M")))
return None
在 shell 上,我正在导入并运行为"sample_code.delay()"
完整错误堆栈:
[2016-02-12 00:28:56,331: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?
The full contents of the message body was: body: 'x80x02}qx01(Ux07expiresqx02NUx03utcqx03x88Ux04argsqx04]qx05Ux05chordqx06NUtcallbacksqx07NUx08errbacksqx08NUx07tasksetqtNUx02idqnU$f02e662e-4eda-4180-9af4-2c8a1ceb57c4qx0bUx07retriesqx0cKx00Ux04taskqrU$app.tasks.sample_codeqx0eUttimelimitqx0fNNx86Ux03etaqx10NUx06kwargsqx11}qx12u.' (232b)
{content_type:u'application/x-python-serialize' content_encoding:u'binary'
delivery_info:{'consumer_tag': u'None4', 'redelivered': False, 'routing_key': u'celery', 'delivery_tag': 8, 'exchange': u'celery'} headers={}}
请让我知道我错在哪里
对我来说解决
的方法是更改运行芹菜的命令
它给出了以下问题:
celery -A <app_path> worker --loglevel=DEBUG
但是如果我们使用:
celery -A <app_path> worker -l info
如果他们面临同样的问题,可能会对其他人有所帮助。