Asynchronous Tasks

Celery tasks of the orchestrator app, and how everything else queues them.

  • execute: execute an Orchestrator’s run.

  • queue: the queue_* functions, the one place that queues these tasks (ADR-030, rule 10, issue #1098).

The package exports the queue_* functions, never a task. Importing queue imports the task module, so that Celery registers its task, which names itself smarter.apps.orchestrator.tasks.<function> (TASK_NAME_PREFIX), the name it had when it was defined in this module.

smarter.apps.orchestrator.tasks.queue_execute_orchestration_run(orchestrator, user_profile, objective)[source]

Start a run of the Orchestrator: check that it may start, record it, and queue execute_orchestration_run().

The api’s runs view calls it. The task is queued once the run’s row is committed, so that the worker finds it, and orchestration_run_queued is sent.

run = queue_execute_orchestration_run(orchestrator, user_profile, "Prepare the board pack for Q4 2025.")
Parameters:
  • orchestrator (Orchestrator) – The Orchestrator.

  • user_profile (UserProfile) – The profile of the user who starts it.

  • objective (str) – What the run is to achieve, e.g. “Prepare the board pack for Q4 2025.”

Return type:

OrchestrationRun

Returns:

The run, pending.

Raises:

OrchestrationRefusedError – If the run may not start, from check_may_run().

Queueing the Tasks

The one place that queues the orchestrator app’s Celery tasks.

Every task of the app is queued by a function of this module, never by <task>.delay() or <task>.apply_async() anywhere else (ADR-030, rule 10, issue #1098). So this module is where to look for what queues a task, and the one place that a test patches so that nothing reaches a real worker, which would call LLMs, and charge for them.

smarter.apps.orchestrator.tasks.queue.queue_execute_orchestration_run(orchestrator, user_profile, objective)[source]

Start a run of the Orchestrator: check that it may start, record it, and queue execute_orchestration_run().

The api’s runs view calls it. The task is queued once the run’s row is committed, so that the worker finds it, and orchestration_run_queued is sent.

run = queue_execute_orchestration_run(orchestrator, user_profile, "Prepare the board pack for Q4 2025.")
Parameters:
  • orchestrator (Orchestrator) – The Orchestrator.

  • user_profile (UserProfile) – The profile of the user who starts it.

  • objective (str) – What the run is to achieve, e.g. “Prepare the board pack for Q4 2025.”

Return type:

OrchestrationRun

Returns:

The run, pending.

Raises:

OrchestrationRefusedError – If the run may not start, from check_may_run().

Executing a Run

The Celery task that executes an Orchestrator’s run (ADR-037).

It is queued by smarter.apps.orchestrator.tasks.queue.queue_execute_orchestration_run(), never with .delay() (ADR-030, rule 10).