airflow.providers.common.ai.triggers.llm_batch

Trigger that polls a @task.llm_batch batch until it reaches a terminal state.

Classes

LLMBatchTrigger

Poll a batch adapter until the batch reaches a terminal state.

Module Contents

class airflow.providers.common.ai.triggers.llm_batch.LLMBatchTrigger(*, llm_conn_id, adapter, batch_id, poll_interval, end_time, cancel_on_kill, cancel_on_timeout, timeout=0)[source]

Bases: airflow.triggers.base.BaseTrigger

Poll a batch adapter until the batch reaches a terminal state.

Deliberately thin: this trigger only polls and, on kill or timeout, cancels. It never downloads or validates results; that is execute_complete()’s job, back on the worker, so a 100k-row download never runs inside the triggerer (a shared process serving many tasks).

Parameters:
  • llm_conn_id (str) – Airflow connection ID, re-resolved into a live adapter via build_adapter() (adapters are not serializable, so only the connection id travels).

  • adapter (str) – The already-resolved adapter name ("openai" / "anthropic"), not the adapter class or instance.

  • batch_id (str) – The provider batch id to poll.

  • poll_interval (int) – Seconds to sleep between polls.

  • end_time (float) – Wall-clock deadline (time.time() epoch seconds). Wall-clock, not time.monotonic(), because this trigger is serialized to the metadata DB and may resume in a different triggerer process after a restart.

  • timeout (int) – The configured budget in seconds, used only to build the timeout message.

  • cancel_on_kill (bool) – Cancel the batch from on_kill when the deferred task is killed. Only takes effect on Airflow 3.3+, which is the first version whose triggerer calls a trigger’s on_kill.

  • cancel_on_timeout (bool) – Cancel the batch when end_time passes without the batch reaching a terminal state. When False, the task still fails with a timeout event, but the batch is left running (and billing) and a later retry re-attaches to it.

llm_conn_id[source]
adapter[source]
batch_id[source]
poll_interval[source]
end_time[source]
timeout = 0[source]
cancel_on_kill[source]
cancel_on_timeout[source]
serialize()[source]

Serialize trigger arguments and class path.

async on_kill()[source]

Cancel the batch when a user kills the deferred task.

Runs in the triggerer event loop on Airflow 3.3+ only; older versions never call a trigger’s on_kill, so a killed deferred task’s batch is not cancelled automatically there. Both the connection lookup and the cancel call are blocking I/O, so both run off the event loop.

async run()[source]

Poll the batch status and yield exactly one terminal event.

Was this entry helpful?