장고 1.11과 Celery 4.1 프로젝트가 있으며, setup docs에 따라 구성했습니다.Celery 4가 자동 검색 작업이 아닙니다.
.env/bin/celery worker -A myproject -l info
가 더 작업 샘플 "debug_task"를 제외하고 발견하는 모습 내가 셀러리 여러 설치된 앱이 비록 : 내가 가진 노동자를 시작할 때
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings.settings'
app = Celery('myproject')
app.config_from_object('django.conf:settings', namespace='CELERY')
#app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) # does nothing
app.autodiscover_tasks() # also does nothing
print('Registering debug task...')
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
,
처럼 내celery_init.py
보인다 작업은
app.autodiscover_task()
에 대한 호출을 통해 발견되었을 것입니다. 이것은 내 근로자는 초기 출력을 생성한다 : 내 응용 프로그램에서
-------------- [email protected] v4.1.0 (latentcall)
---- **** -----
--- * *** * -- Linux-4.13.0-16-generic-x86_64-with-Ubuntu-16.04-xenial 2017-10-31 15:56:42
-- * - **** ---
- ** ---------- [config]
- ** ---------- .> app: myproject:0x7f952856d650
- ** ---------- .> transport: amqp://guest:**@localhost:5672//
- ** ---------- .> results: amqp://
- *** --- * --- .> concurrency: 4 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. myproject.celery_init.debug_task
[2017-10-31 15:56:42,180: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2017-10-31 15:56:42,188: INFO/MainProcess] mingle: searching for neighbors
[2017-10-31 15:56:43,211: INFO/MainProcess] mingle: all alone
[2017-10-31 15:56:43,237: INFO/MainProcess] [email protected] ready.
내 모든 레거시 작업 tasks.py
파일을 다음과 같이 정의했다 :
from celery.task import task
@task(name='mytask')
def mytask():
blah
워드 프로세서 shared_task
장식을 사용하는 것이 좋습니다, 그래서 대신 내가 시도 :
from celery import shared_task
@shared_task
def mytask():
blah
하지만 셀러리 작업자는 여전히 그것을 보지 못합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
편집 : 내 설정의 CELERY_IMPORTS
목록에 명시 적으로 나열하여 작업을 표시 할 수 있었지만 그래도 tasks.py
을 편집하여 Django 프로젝트 (models.py, 등) 또는 예외를 발생시킵니다. Apps aren't loaded yet.
이것은 아무것도 아닌 것보다 낫지 만 엄청난 양의 리팩토링이 필요합니다. 더 좋은 방법이 있습니까?
'Celery Worker -A app.tasks -l DEBUG'을 실행하면 어떻게됩니까? 프로젝트 전체가 아니라 애플 리케이션의 태스크 파일을 지정해야한다는 것을 알았습니다. – Jason