API reference¶
The public API is exported from airflow_ha. HighAvailabilityOperator is an
alias of HighAvailabilitySensor, which extends Airflow’s PythonSensor.
Health results and actions¶
CheckResult is tuple[Result, Action]. A check callable returns a tuple
containing members of both enums.
Result |
Value |
Meaning |
|---|---|---|
|
|
Healthy outcome. |
|
|
Unhealthy outcome. |
Action |
Value |
Meaning |
|---|---|---|
|
|
Continue sensor polling. |
|
|
Trigger another run of the DAG. |
|
|
Finish this monitoring run. |
The callable receives Airflow’s Python callable arguments and task context.
A malformed return value becomes FAIL/STOP. A callable exception stores
FAIL/RETRIGGER in the sensor’s return_value XCom and propagates the exception.
HighAvailabilityOperator¶
HighAvailabilityOperator(
python_callable,
pass_trigger_kwargs=None,
fail_trigger_kwargs=None,
*,
runtime=None,
endtime=None,
maxretrigger=None,
reference_date="data_interval_end",
**kwargs,
)
kwargs contains Airflow PythonSensor arguments, including task_id, dag,
poke_interval, timeout, mode, op_args, op_kwargs, retries, and callbacks.
The sensor’s trigger rule defaults to none_failed.
Limits and reference dates¶
Argument |
Default |
Accepted values and behavior |
|---|---|---|
|
|
Integer seconds or |
|
|
ISO time string or |
|
|
Positive integer; reaching the count changes the action to |
|
|
DagRun attribute: |
None, zero, and negative maxretrigger values leave the retrigger count
unbounded. Limits are evaluated in order: runtime, endtime, then retrigger
count. A reached time limit takes precedence over a failed health result.
The first check uses the selected DagRun reference attribute. A retrigger writes
the original run’s start_date to <task_id>-referencedate in the next run’s
configuration; subsequent retriggers preserve that timestamp. A supplied
<task_id>-referencedate ISO datetime overrides the selected attribute.
endtime is combined with the reference date’s calendar day in the DAG’s
timezone. It is not a rolling cutoff on the current day.
Generated tasks and branching¶
An operator named health creates seven tasks:
Task |
Behavior |
|---|---|
|
Runs the check callable as a sensor. |
|
Selects an outcome branch; trigger rule |
|
Creates another DAG run after a healthy result. |
|
Creates another DAG run after an unhealthy result. |
|
Raises a failure after the failed retrigger succeeds. |
|
Completes successfully without retriggering. |
|
Raises a failure without retriggering. |
Stored result and action |
Selected branch |
|---|---|
|
|
|
|
|
|
|
|
CONTINUE keeps the sensor polling. If the sensor then times out, the decide
task changes CONTINUE to RETRIGGER, preserving its last health result.
Missing or malformed stored XCom results become FAIL/RETRIGGER. Exhausting
maxretrigger selects the stop branch for that result. Time limits instead
select stop_pass.
Branch properties¶
decide_task, stop_fail, stop_pass, retrigger_fail, and retrigger_pass
return the corresponding generated operators. check_end_conditions returns
the configured limit-check callable. get_retrigger_count(**context) reads the
integer count from DagRun configuration. is_initial_run(**context) returns
whether that count is zero.
Retrigger configuration¶
pass_trigger_kwargs and fail_trigger_kwargs supply keyword arguments to
their TriggerDagRunOperator. trigger_dag_id defaults to the current DAG ID;
trigger_rule defaults to one_success. Each mapping’s conf accepts a
dictionary or a templated JSON-object string.
The integration adds <task_id>-retrigger with the incremented count and
<task_id>-referencedate with the retained timestamp. These keys override
matching user values. The constructor removes conf from supplied kwargs
mappings and modifies dictionary configuration values in place.
Callbacks¶
Explicit on_failure_callback, on_retry_callback, on_execute_callback,
on_success_callback, and on_skipped_callback arguments apply to the sensor
and generated branch tasks. Omitted arguments use each task’s inherited DAG
default_args. Callbacks supplied in pass_trigger_kwargs or
fail_trigger_kwargs override the corresponding retrigger task’s callback.
Callbacks receive the executing task’s context. A failure result can complete the sensor successfully before a generated failure task raises its exception. Several tasks can invoke a callback in one run; a success callback does not imply success of the complete DAG. Callback support also depends on the installed Airflow version and its task-state handling.
DAG parameters and run configuration¶
Parameter |
Default |
Current behavior |
|---|---|---|
|
|
Bypasses runtime, endtime, and count limits. |
|
|
Overrides runtime with integer seconds. |
|
|
Overrides endtime with an ISO time string. |
|
|
Overrides the count limit when positive. |
|
|
Registered but not read by current branch selection. |
dag_run.conf["airflow_ha_force_run"] also bypasses all three limits.
Parameter values are read from task context params; Airflow’s configuration
controls whether run configuration overrides those values.
Runtime override integers are normalized to timedelta; endtime override strings
are normalized to datetime.time. A null override leaves the configured limit
in effect. A runtime override of zero applies a zero-second budget. Both sensor
polling and branch selection use the sensor task ID to look up these parameters.
Declarative task models¶
HighAvailabilityTaskArgs extends airflow_pydantic.PythonSensorArgs.
HighAvailabilityTask adds the declarative task interface and defaults its
operator to airflow_ha.HighAvailabilitySensor.
HighAvailabilitySensorTaskArgs and HighAvailabilitySensorTask are aliases.
The model schema defaults runtime to 120 seconds, maxretrigger to 2,
and reference_date to data_interval_end. Both trigger kwargs and endtime
default to None. Only explicitly set fields are forwarded when tasks are
instantiated or rendered; omitted limits use the native operator’s defaults.
See the how-to guides for Python and airflow-config examples.
Generated API¶
|
|
|
|
Built-in immutable sequence. |
|
|
|
alias of |
|
Args for the HighAvailabilityTask. |
|
alias of |
|
alias of |