39👍
Now in Celery 4.1 you can solve that problem by that code(the easiest way):
import celeryconfig
from celery import Celery
app = Celery()
app.config_from_object(celeryconfig)
For Example small celeryconfig.py :
BROKER_URL = 'pyamqp://'
CELERY_RESULT_BACKEND = 'redis://localhost'
CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}
Also very simple way:
from celery import Celery
app = Celery('tasks')
app.conf.update(
result_expires=60,
task_acks_late=True,
broker_url='pyamqp://',
result_backend='redis://localhost'
)
Or Using a configuration class/object:
from celery import Celery
app = Celery()
class Config:
enable_utc = True
timezone = 'Europe/London'
app.config_from_object(Config)
# or using the fully qualified name of the object:
# app.config_from_object('module:Config')
Or how was mentioned by setting CELERY_CONFIG_MODULE
import os
from celery import Celery
#: Set default configuration module name
os.environ.setdefault('CELERY_CONFIG_MODULE', 'celeryconfig')
app = Celery()
app.config_from_envvar('CELERY_CONFIG_MODULE')
Also see:
- Create config: http://docs.celeryproject.org/en/latest/userguide/application.html#configuration
- Configuration fields: http://docs.celeryproject.org/en/latest/userguide/configuration.html
22👍
I had a similar problem with my tasks module. A simple
# celery config is in a non-standard location
import os
os.environ['CELERY_CONFIG_MODULE'] = 'mypackage.celeryconfig'
in my package’s __init__.py
solved this problem.
- [Django]-Django accessing ForeignKey model objects
- [Django]-"{% extends %}" and "{% include %}" in Django Templates
- [Django]-Django- nginx: [emerg] open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/sites-enabled/myproject:11
3👍
Make sure you have celeryconfig.py in the same location you are running ‘celeryd’ or otherwise make sure its is available on the Python path.
- [Django]-How to switch Python versions in Terminal?
- [Django]-Celery: When should you choose Redis as a message broker over RabbitMQ?
- [Django]-Django MultiValueDictKeyError error, how do I deal with it
3👍
you can work around this with the environment… or, use –config: it requires
- a path relative to CELERY_CHDIR from /etc/defaults/celeryd
- a python module name, not a filename.
The error message could probably use these two facts.
- [Django]-How to see which tests were run during Django's manage.py test command
- [Django]-Cron and virtualenv
- [Django]-How to generate list of response messages in Django REST Swagger?
Source:stackexchange.com