Django App中的Celery Task发现仅部分起作用

时间:2019-03-26 13:41:27

标签: python django python-3.x celery django-celery

对于任务发现,我有一个很奇怪的问题,即任务发现仅在Django应用中部分起作用。

我有一个结构如下的应用程序:

app\
 |>celery.py
  >tasks\
   |>__init__.py
   |>a.py
   |>b.py
   |>c.py

celery.py:

class CeleryAppConfig(AppConfig):
    name = 'taskapp'
    verbose_name = 'Celery Config'

    def ready(self):
        installed_apps = [app_config.name for app_config in apps.get_app_configs()]
        app.autodiscover_tasks(lambda: installed_apps, force=True)

Init.py:

from .a import *
from .b import *
from .c import *

a.py b.py和c.py @

from celery import shared_task

@shared_task(bind=True)
def Task(self):
    #do stuff.

问题是,尽管a.py和b.py中的任务是自动发现的,但c.py中的任务却没有。

将函数从c.py复制到a.py意味着可以识别该函数,反之则不然。

我最终可以使它工作而无需在多个文件中执行任务,但是它超级烦人。我在带有django 2和celery 4.2的高山上运行python 3.6

0 个答案:

没有答案