我最近将celery == 3.1.0与我们公司的django项目整合在一起。请在下面找到目录结构和一些代码详细信息。
website/apps/__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 website.settings.celery import app as celery_app
:
website/settings/celery.py
from __future__ import absolute_import
from django.conf import settings
from celery import Celery
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings.local')
app = Celery('website.apps')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(settings.INSTALLED_APPS)
# @signals.setup_logging.connect
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
:
website/apps/app1/tasks.py
from __future__ import absolute_import
from celery import shared_task
@shared_task
def add(x, y):
return x + y
:
website/settings/base.py
BROKER_URL = 'amqp://guest:guest@localhost//'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERYD_HIJACK_ROOT_LOGGER = False
CELERYD_LOG_FILE = None
CELERY_REDIRECT_STDOUTS = False
CELERYD_LOG_LEVEL = 0
中的芹菜设置:
Assignment Task
目前,我已经在我的机器上设置了DEBUG = True。运行python manage.py runserver后,我在控制台上看不到任何调试日志。我只看到请求的URL和提供的静态文件。在celery安装之前,我能够查看正在执行的SQL查询的调试日志。我正在使用django == 1.4.12。任何帮助将不胜感激。