简体   繁体   中英

'module' object has no attribute 'celery'

I've been reading through the answers to some previous questions as well as the celery docs and I just can't quite fix this issue. My task.py, celery.py, and settings.py are all contained within the same app RBWebfiles which is contained within the project called recruiting board. I'm attempting to creating a periodic-task that will run using celery beat's scheduler.

This is the portion of my settings.py that deals with celery:

from __future__ import absolute_import
import os
from datetime import timedelta


CELERY_IMPORTS = ('RBWebfiles.tasks')

CELERYBEAT_SCHEDULE = 'djcelery.schedulers.DatabaseScheduler'
CELERYBEAT_SCHEDULE = {
    'schedule-name':{
        'task': 'RBWebfiles.tasks.requestRefresher',
        'schedule': timedelta(seconds = 30),
    },
}

BROKER_URL = 'django://'

I also added 'djcelery' to my installed apps within that file

This is my tasks.py file:

from __future__ import absolute_import
import datetime
from celery.task.base import periodic_task
from student.models import StudentAccount
from celery import Celery
from celery.utils.log import get_task_logger
import os

celery = Celery('tasks', broker='django://')
logger = get_task_logger(__name__)


os.environ['DJANGO_SETTINGS_MODULE'] = 'RBWebfiles.settings'


@periodic_task(run_every=datetime.timedelta(seconds=30))
def requestRefresher(self):
    logger.info("start task")
    for s in StudentAccount.objects.all():
        s.requestLimit = 0
        s.save()
    return None

and lastly this is my celery.py file:

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'conf.settings')
app = Celery('RBWebfiles.celery')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda : settings.INSTALLED_APPS)

app.conf.update(
    CELERY_RESULT_BACKEND ='djcelery.backends.database:DatabaseBackend',
)

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

I've tried uninstalling and reinstalling both celery and django-celery, I'm not sure if I just don't understand something or I'm making a massive error. I attempt to run it using the command : celery beat -A RBWebfiles

this is the traceback:

C:\Users\Lexie Infantino\PycharmProjects\recruitingboard>celery beat -A   RBWebfiles
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\celery\app\utils.py", line 235, in     find_app
    found = sym.app
AttributeError: 'module' object has no attribute 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\celery.exe\__main__.py", line 9, in <module>
  File "C:\Python34\lib\site-packages\celery\__main__.py", line 30, in main
    main()
  File "C:\Python34\lib\site-packages\celery\bin\celery.py", line 81, in     main
    cmd.execute_from_commandline(argv)
  File "C:\Python34\lib\site-packages\celery\bin\celery.py", line 769, in     execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "C:\Python34\lib\site-packages\celery\bin\base.py", line 309, in     execute_from_commandline
   argv = self.setup_app_from_commandline(argv)
  File "C:\Python34\lib\site-packages\celery\bin\base.py", line 469, in     setup_app_from_commandline
    self.app = self.find_app(app)
  File "C:\Python34\lib\site-packages\celery\bin\base.py", line 489, in     find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "C:\Python34\lib\site-packages\celery\app\utils.py", line 240, in     find_app
    found = sym.celery
AttributeError: 'module' object has no attribute 'celery'

确保djcelery在您的INSTALLED_APPS中,然后尝试使用manage.py celerybeat来启动celery beat。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM