0
votes

in my tasks.py file I want to import models from polls app, but I get django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet when starting the worker

tasks.py

from __future__ import absolute_import
import sys ,os
from polls.models import User
from .celery import app


@app.task
def add_user(user):
    # for user in users:
    print('urra')
    #user = User(user.first_name, user.last_name, user.email)
    # user.save()

celery.py:

from __future__ import absolute_import, unicode_literals
from celery import Celery
import os, sys
from task import celery_config
import dotenv
from os.path import dirname, join

app = Celery('task',
             broker='amqp://root:lusine_admin@localhost/task',
             backend='amqp://',
             include=['task.tasks'])

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "task.settings")
app.config_from_object(celery_config)
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

if __name__ == '__main__':
    app.start()

Actaually I got error polls module not found, but then from bash I added it to pythonpath and know I get this error.

1
share your full trace back please. - Saiful Azad

1 Answers

0
votes

Your error is with your config. If you want to connect celery with your django, you have to initialize the celery config from the django settings. In your celery.py replace this line:

app.config_from_object(celery_config)

with

app.config_from_object('django.conf:settings', namespace='CELERY')