I'm using Django, Celery, and RabbitMQ. When I run celery -A FlakeFinder worker -l INFO
from the top level directory, I get the error:
Usage: celery [OPTIONS] COMMAND [ARGS]...
Error: Invalid value for '-A' / '--app':
Unable to load celery application.
Module 'flakefinder' has no attribute 'celery'
If I instead run celery -A FlakeFinder.celeryApp worker -l INFO
, I get this error in purple text:
ModuleNotFoundError: No module named 'celery.backends.amqp'
I'm not really sure where to go from here. How can I get the celery worker running?
My folder structure looks like this:
. (FlakeFinder)
├── FlakeFinder
│ ├── __init__.py
│ ├── asgi.py
│ ├── celeryApp.py
│ ├── secrets.py
│ ├── settings.py
│ ├── tasks.py
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── license.txt
├── manage.py
├── scraping
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ ├── models.py
│ ├── scraper.py
│ ├── tests.py
│ └── views.py
celeryApp.py
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery.schedules import crontab # scheduler
# default django settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FlakeFinder.settings')
app = Celery('FlakeFinder')
app.conf.timezone = 'UTC'
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
app.conf.beat_schedule = {
# executes every 1 minute
'scraping-task-three-hr': {
'task': 'scraping.tasks',
'schedule': crontab()
}
}
tasks.py
from scraping.scraper import *
from celeryApp import app
@app.task
def update_snow_locs():
...
尝试将“celeryApp.py”的名称更改为“celery.py”
I couldn't figure out how to get past this. I solved the issue by downgrading to version 4.4.2.
The AMQP result backend is scheduled for deprecation in version 4.0 and removal in version v5.0. Please use RPC backend or a persistent backend.
The error seems to be quite clear.
from celery import Celery
from celery import task
celery = Celery('tasks', broker='amqp://guest@localhost//') #!
import os
os.environ[ 'DJANGO_SETTINGS_MODULE' ] = "proj.settings"
@task()
def add_photos_task( lad_id ):
...
This is what I found online with the explanation - "forgot to create a celery object in tasks.py" But no means I am an expert in Celery Module.
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.