Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/celery_backend/config.py
Show All 11 Lines | |||||
from celery.utils.log import ColorFormatter | from celery.utils.log import ColorFormatter | ||||
from celery.worker.control import Panel | from celery.worker.control import Panel | ||||
from kombu import Exchange, Queue | from kombu import Exchange, Queue | ||||
from kombu.five import monotonic as _monotonic | from kombu.five import monotonic as _monotonic | ||||
import requests | import requests | ||||
from swh.scheduler import CONFIG as SWH_CONFIG | |||||
from swh.core.config import load_named_config, merge_configs | from swh.core.config import load_named_config, merge_configs | ||||
from swh.core.logger import JournalHandler | from swh.core.logger import JournalHandler | ||||
DEFAULT_CONFIG_NAME = 'worker' | DEFAULT_CONFIG_NAME = 'worker' | ||||
CONFIG_NAME_ENVVAR = 'SWH_WORKER_INSTANCE' | CONFIG_NAME_ENVVAR = 'SWH_WORKER_INSTANCE' | ||||
CONFIG_NAME_TEMPLATE = 'worker/%s' | CONFIG_NAME_TEMPLATE = 'worker/%s' | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | def register_task_class(app, name, cls): | ||||
task_instance = cls() | task_instance = cls() | ||||
task_instance.name = name | task_instance.name = name | ||||
app.register_task(task_instance) | app.register_task(task_instance) | ||||
INSTANCE_NAME = os.environ.get(CONFIG_NAME_ENVVAR) | INSTANCE_NAME = os.environ.get(CONFIG_NAME_ENVVAR) | ||||
CONFIG_NAME = os.environ.get('SWH_CONFIG_FILENAME') | CONFIG_NAME = os.environ.get('SWH_CONFIG_FILENAME') | ||||
CONFIG = {} | CONFIG = {} | ||||
if CONFIG_NAME: | if CONFIG_NAME: | ||||
# load the celery config from the main config file given as | # load the celery config from the main config file given as | ||||
# SWH_CONFIG_FILENAME environment variable. | # SWH_CONFIG_FILENAME environment variable. | ||||
# This is expected to have a [celery] section in which we have the | # This is expected to have a [celery] section in which we have the | ||||
# celery specific configuration. | # celery specific configuration. | ||||
CONFIG = load_named_config(CONFIG_NAME).get('celery') | SWH_CONFIG.clear() | ||||
SWH_CONFIG.update(load_named_config(CONFIG_NAME)) | |||||
CONFIG = SWH_CONFIG.get('celery') | |||||
if not CONFIG: | if not CONFIG: | ||||
# otherwise, back to compat config loading mechanism | # otherwise, back to compat config loading mechanism | ||||
if INSTANCE_NAME: | if INSTANCE_NAME: | ||||
CONFIG_NAME = CONFIG_NAME_TEMPLATE % INSTANCE_NAME | CONFIG_NAME = CONFIG_NAME_TEMPLATE % INSTANCE_NAME | ||||
else: | else: | ||||
CONFIG_NAME = DEFAULT_CONFIG_NAME | CONFIG_NAME = DEFAULT_CONFIG_NAME | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |