在Django视图中的一个 POST API中,我有以下内容:
data_processing.apply_async(
args=[data], queue='image', countdown=10
)
在芹菜任务中,我有:
@shared_task
def data_processing(data):
dataid = data['dataid']
print "ABSBBSBBB"
print "ANSNNDNDN"
在POST数据期间没有错误,但是print语句不起作用。控制台上没有打印任何内容,但数据POSTing成功。
非常感谢任何帮助 !!!
修改:在celery.py中,我有以下内容:
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings # noqa
from kombu import Queue
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.development')
app = Celery('config')
app.conf.update(
BROKER_URL='.....',
CELERY_ACCEPT_CONTENT=['json'],
CELERY_TASK_SERIALIZER='json',
CELERY_RESULT_SERIALIZER='json',
CELERY_QUEUES=(
Queue('default', routing_key='default'),
Queue('image', routing_key='image'),
),
CELERY_DEFAULT_QUEUE='default',
CELERY_DEFAULT_EXCHANGE='default',
CELERY_DEFAULT_ROUTING_KEY='default',
CELERY_MAX_RETRY=3,
CELERY_RETRY_COUNTDOWN=60*15,
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
在config / init .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