Skip to content

climate_ref_celery.app #

Celery app creation

create_celery_app(name) #

Create a Celery app

This function creates a new Celery app with the given name and configuration module. The configuration module is loaded from the environment variable CELERY_CONFIG_MODULE which defaults to climate_ref_celery.celeryconf.dev if not set.

Source code in packages/climate-ref-celery/src/climate_ref_celery/app.py
def create_celery_app(name: str) -> Celery:
    """
    Create a Celery app

    This function creates a new Celery app with the given name and configuration module.
    The configuration module is loaded from the environment variable `CELERY_CONFIG_MODULE`
    which defaults to `climate_ref_celery.celeryconf.dev` if not set.
    """
    app = Celery(name)
    app.config_from_envvar("CELERY_CONFIG_MODULE")

    return app

setup_logging_handler(loglevel, **kwargs) #

Set up logging for the Celery worker using the celery signal

Source code in packages/climate-ref-celery/src/climate_ref_celery/app.py
@setup_logging.connect
def setup_logging_handler(loglevel: int, **kwargs: Any) -> None:  # pragma: no cover
    """Set up logging for the Celery worker using the celery signal"""
    # We ignore the format passed by Celery instead using our own configuration
    config = Config.default()
    msg_format = config.log_format

    initialise_logging(level=loglevel, format=msg_format, log_directory=config.paths.log)

worker_ready_handler(**kwargs) #

Log a message when the worker is ready

Source code in packages/climate-ref-celery/src/climate_ref_celery/app.py
@worker_ready.connect
def worker_ready_handler(**kwargs: Any) -> None:  # pragma: no cover
    """
    Log a message when the worker is ready
    """
    config = Config.default()
    logger.info(f"Worker ready with config {pretty_repr(config)}")