31👍
I forgot to create a celery object in tasks.py:
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 ):
...
After that we could normally start tasks:
celery -A tasks worker --loglevel=info
19👍
For anyone who is getting the same error message for an apparently different reason, note that if any of the imports in your initialization file fail, your app will raise this totally ambiguous AttributeError
rather than the exception that initially caused it.
- [Django]-Is there a way to filter a queryset in the django admin?
- [Django]-Import Error: No module named django
- [Django]-Django debug display all variables of a page
12👍
Celery uses celery
file for storing configuration of your app, you can’t just give a python file with tasks and start celery.
You should define celery
file ( for Celery>3.0; previously it was celeryconfig.py
)..
celeryd –app app.celery -l info
This example how to start celery with config file at app/celery.py
Here is example of celery file: https://github.com/Kami/libcloud-sandbox/blob/master/celeryconfig.py
- [Django]-Django DoesNotExist
- [Django]-Django Model set foreign key to a field of another Model
- [Django]-How to show query parameter options in Django REST Framework – Swagger
3👍
My problem was that I put the celery
variable inside a main function:
if __name__ == '__main__': # Remove this row
app = Flask(__name__)
celery = make_celery(app)
when it should be put outside.
- [Django]-What is dispatch used for in django?
- [Django]-List_display – boolean icons for methods
- [Django]-Which database engine to choose for Django app?
2👍
When you run celery -A tasks worker --loglevel=info
, your celery app should be exposed in the module tasks
. It shouldn’t be wrapped in a function or an if
statements that.
If you make_celery
in another file, you should import the celery app in to your the file you are passing to celery.
- [Django]-Django ImportError: cannot import name 'render_to_response' from 'django.shortcuts'
- [Django]-Users in initial data fixture
- [Django]-Using IntellijIdea within an existing virtualenv
1👍
Try start celery:
celeryd --config=my_app.my_config --loglevel=INFO --purge -Q my_queue
There is next script in my tasks.py
:
@task(name="my_queue", routing_key="my_queue")
def add_photos_task( lad_id ):
There is next script in my_config.py
:
CELERY_IMPORTS = \
(
"my_app.tasks",
)
CELERY_ROUTES = \
{
"my_queue":
{
"queue": "my_queue"
},
}
CELERY_QUEUES = \
{
"my_queue":
{
"exchange": "my_app",
"exchange_type": "direct",
"binding_key": "my_queue"
},
}
celery = Celery(broker='amqp://guest@localhost//')
- [Django]-How do you change the default widget for all Django date fields in a ModelForm?
- [Django]-Paginator for inline models in django admin
- [Django]-Cannot access django app through ip address while accessing it through localhost