Моя задача сельдерея - обновить базу данных mongodb. Я создал для него обработчик, который импортирую в celery.py. Кажется, что сельдерей работает нормально, но когда я пытаюсь импортировать модуль обработчика, он выдает ошибку. django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet
celery.py:
from __future__ import absolute_import, unicode_literals
from django.conf import settings
import os
from celery import Celery
# from handlers.ordercount import OrderCount
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'di_idealsteel.settings')
app = Celery('di_idealsteel')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
app.config_from_object('django.conf:settings')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
@app.task(bind=True)
def add(self,number,customer_id):
ordercount = OrderCount()
opencount = ordercount.open_enquiries(number,customer_id)
Когда я пытаюсь импортировать 5-ю строку , он выдает эту ошибку
Traceback (most recent call last):
File "c:\users\ashish\envs\idealvenv\lib\site-packages\celery\app\trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "c:\users\ashish\envs\idealvenv\lib\site-packages\celery\app\trace.py", line 437, in __protected_call__
return self.run(*args, **kwargs)
File "C:\Users\Ashish\Desktop\Internship\di_idealsteel\di_idealsteel\celery.py", line 32, in add
from handlers.ordercount import OrderCount
File "C:\Users\Ashish\Desktop\Internship\di_idealsteel\handlers\ordercount.py", line 4, in <module>
from handlers.user_handler import UserHandler
File "C:\Users\Ashish\Desktop\Internship\di_idealsteel\handlers\user_handler.py", line 12, in <module>
from app.models import (AuthUser,Customers,CustomerUsers,UserHistory,CustomerUsersHistory)
File "C:\Users\Ashish\Desktop\Internship\di_idealsteel\app\models.py", line 10, in <module>
from django.contrib.auth.models import User
File "c:\users\ashish\envs\idealvenv\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "c:\users\ashish\envs\idealvenv\lib\site-packages\django\contrib\auth\base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "c:\users\ashish\envs\idealvenv\lib\site-packages\django\db\models\base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "c:\users\ashish\envs\idealvenv\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "c:\users\ashish\envs\idealvenv\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Другие файлы:
__init__.py:
from __future__ import absolute_import, unicode_literals
# 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
__all__ = ('celery_app',)
settings.py :
# CELERY STUFF
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Africa/Nairobi'