现在在Celery 4.1中,您可以通过该代码解决该问题(最简单的方法):
import celeryconfig from celery import Celery app = Celery() app.config_from_object(celeryconfig)
例如,小celeryconfig.py:
BROKER_URL = 'pyamqp://' CELERY_RESULT_BACKEND = 'redis://localhost' CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}
也很简单的方法:
from celery import Celery app = Celery('tasks') app.conf.update( result_expires=60, task_acks_late=True, broker_url='pyamqp://', result_backend='redis://localhost' )
或者使用配置类/对象:
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')
或者通过设置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')
另见:
创建配置: http ://docs.celeryproject.org/en/latest/userguide/application.html#configuration
配置字段: http ://docs.celeryproject.org/en/latest/userguide/configuration.html
basti.. 21
我的任务模块遇到了类似的问题.一个简单的
# celery config is in a non-standard location import os os.environ['CELERY_CONFIG_MODULE'] = 'mypackage.celeryconfig'
在我的包中__init__.py
解决了这个问题.
现在在Celery 4.1中,您可以通过该代码解决该问题(最简单的方法):
import celeryconfig from celery import Celery app = Celery() app.config_from_object(celeryconfig)
例如,小celeryconfig.py:
BROKER_URL = 'pyamqp://' CELERY_RESULT_BACKEND = 'redis://localhost' CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}
也很简单的方法:
from celery import Celery app = Celery('tasks') app.conf.update( result_expires=60, task_acks_late=True, broker_url='pyamqp://', result_backend='redis://localhost' )
或者使用配置类/对象:
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')
或者通过设置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')
另见:
创建配置: http ://docs.celeryproject.org/en/latest/userguide/application.html#configuration
配置字段: http ://docs.celeryproject.org/en/latest/userguide/configuration.html
我的任务模块遇到了类似的问题.一个简单的
# celery config is in a non-standard location import os os.environ['CELERY_CONFIG_MODULE'] = 'mypackage.celeryconfig'
在我的包中__init__.py
解决了这个问题.