Skip to content

api.siibra_api_config

This module houses the configuration of siibra-api.

This should be the only place where user can influence the configuration of siibra-api.

As siibra-api will attempt to load this module, user can either configure siibra-api with environment variables, or overwrite the this file directly (with docker volume mount, for example).

CELERY_CHANNEL = os.environ.get('SIIBRA_API_CELERY_CHANNEL', f'siibra-api-{__version__}') module-attribute

CELERY_CHANNEL

GIT_HASH = os.getenv('GIT_HASH', 'unknown-hash') module-attribute

GIT_HASH

MONITOR_FIRSTLVL_DIR = os.getenv('MONITOR_FIRSTLVL_DIR') or os.getenv('_MONITOR_FIRSTLVL_DIR') module-attribute

MONITOR_FIRSTLVL_DIR

NAME_SPACE = os.environ.get('SIIBRA_API_NAMESPACE', 'siibraapi') module-attribute

NAME_SPACE

QUEUE_PREFIX = f'{__version__}.{NAME_SPACE}' module-attribute

QUEUE_PREFIX

REDIS_HOST = os.getenv('SIIBRA_API_REDIS_HOST') or os.getenv('SIIBRA_REDIS_SERVICE_HOST') or os.getenv('REDIS_SERVICE_HOST') or os.getenv('REDIS_HOST') or 'localhost' module-attribute

REDIS_HOST

REDIS_PASSWORD = os.getenv('SIIBRA_API_REDIS_PASSWORD') module-attribute

REDIS_PASSWORD

REDIS_PORT = os.getenv('SIIBRA_API_REDIS_PORT') or os.getenv('SIIBRA_REDIS_SERVICE_PORT') or os.getenv('REDIS_SERVICE_PORT') or os.getenv('REDIS_PORT') or 6379 module-attribute

REDIS_PORT

ROLE = os.environ.get('SIIBRA_API_ROLE', 'all') module-attribute

ROLE

__version__ = _config_hash and f'c.{_config_hash}' or __version__ module-attribute

siibra api version

CELERY_CONFIG

CELERY_CONFIG

Source code in api/siibra_api_config.py
class CELERY_CONFIG:
    """CELERY_CONFIG"""
    broker_url=os.getenv("SIIBRA_API_CELERY_BROKER", f"redis://{(':' + REDIS_PASSWORD + '@') if REDIS_PASSWORD else ''}{REDIS_HOST}:{REDIS_PORT}")
    result_backend=os.getenv("SIIBRA_API_CELERY_RESULT", f"redis://{(':' + REDIS_PASSWORD + '@') if REDIS_PASSWORD else ''}{REDIS_HOST}:{REDIS_PORT}")
    result_expires=60
    worker_send_task_events = True
    task_send_sent_event = True

    # see https://docs.celeryq.dev/en/stable/userguide/optimizing.html#reserve-one-task-at-a-time
    task_acks_late = True
    worker_prefetch_multiplier = 1

    # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_time_limit
    # some long running tasks can take a while, but should not exceed 10 minutes to run
    task_time_limit = 600

    include=['api.common.data_handlers', 'api.serialization']

    # source of truth on all queues
    task_routes={
        f'api.common.data_handlers.{queue}.*': f'{QUEUE_PREFIX}.{queue}'
        for queue in queues
    }

    # define task_queues explicitly, so that if -Q is not defined, the worker
    # will pick up all tasks
    task_queues = {
        'celery': {}, # default queue
        **{
            route: {}
            for route in task_routes.values()
        }
    }