amrx
amrx

Reputation: 713

Celery Config file location

Celery documentation says that the configuration file should be in the working directory or in python path.

from celery import Celery
from properties import config_file
import sys


sys.path.append(config_file)
app = Celery()
app.config_from_object(config_file.split('.')[0])

Here config_file is /opt/celery/celery_config.py. The idea is to give user the freedom to create config file. The documentation says that config file should either be in working directory or in sys path. I added the config_file in sys path, but when worker is started, it is throwing import error.

Is it necessary to have the config_file in the same directory as the module that creates Celery instance?

Upvotes: 3

Views: 9501

Answers (1)

Chillar Anand
Chillar Anand

Reputation: 29514

It is not necessary to have config in the same directory.

Simple solution is to change directory when starting celery worker. If you are using supervisor or any other tool to start worker, you can specify the directory where you want to run the worker.

In this case, you can specify directory as /opt/celery and celery command as celery worker -l info --config=celery_config which will pick configuration from /opt/celery/celery_config.py.

Alternatively, you can add that directory to sys.path. In your celery module, append the directory to sys.path.

import sys

from celery import Celery


sys.path.append('/opt/celery/')


app = Celery()
app.config_from_object('celery_config')

This will pick configuration from /opt/celery/celery_config.py.

Upvotes: 1

Related Questions