Skip to content

climate_ref_celery.worker_tasks #

Celery worker tasks for handling diagnostic execution executions.

handle_result(result, execution_id) #

Handle the result of a diagnostic execution

This function is called when a diagnostic execution is completed.

Parameters:

Name Type Description Default
execution_id int

The unique identifier for the diagnostic execution

required
result ExecutionResult

The result of the diagnostic execution

required
Source code in packages/climate-ref-celery/src/climate_ref_celery/worker_tasks.py
@current_app.task
def handle_result(result: ExecutionResult, execution_id: int) -> None:
    """
    Handle the result of a diagnostic execution

    This function is called when a diagnostic execution is completed.

    Parameters
    ----------
    execution_id
        The unique identifier for the diagnostic execution
    result
        The result of the diagnostic execution
    """
    logger.info(f"Handling result for execution {execution_id} + {result}")

    config = Config.default()
    db = Database.from_config(config, run_migrations=False)

    with db.session.begin():
        execution = db.session.get(Execution, execution_id)

        if execution is None:
            logger.error(f"Execution {execution_id} not found")
            return

        handle_execution_result(config, db, execution, result)