airflow.providers.common.ai.triggers.llm_batch¶
Trigger that polls a @task.llm_batch batch until it reaches a terminal state.
Classes¶
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.BaseTriggerPoll 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, nottime.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_killwhen the deferred task is killed. Only takes effect on Airflow 3.3+, which is the first version whose triggerer calls a trigger’son_kill.cancel_on_timeout (bool) – Cancel the batch when
end_timepasses without the batch reaching a terminal state. WhenFalse, the task still fails with atimeoutevent, but the batch is left running (and billing) and a later retry re-attaches to it.
- 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.