High Availability (HA) DAG Utility
Project description
airflow-ha
High Availability (HA) DAG Utility
Overview
This library provides an operator called HighAvailabilityOperator
, which inherits from PythonSensor
and does the following:
- runs a user-provided
python_callable
as a sensor- if this returns
"done"
, mark the DAG as passed and finish - if this returns
"running"
, keep checking - if this returns
"failed"
, mark the DAG as failed and re-run
- if this returns
- if the sensor times out, mark the DAG as passed and re-run
Consider the following DAG:
from datetime import datetime, timedelta
from random import choice
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow_ha import HighAvailabilityOperator
with DAG(
dag_id="test-high-availability",
description="Test HA Operator",
schedule=timedelta(days=1),
start_date=datetime(2024, 1, 1),
catchup=False,
):
ha = HighAvailabilityOperator(
task_id="ha",
timeout=30,
poke_interval=5,
python_callable=lambda **kwargs: choice(("done", "failed", "running", ""))
)
pre = PythonOperator(task_id="pre", python_callable=lambda **kwargs: "test")
pre >> ha
fail = PythonOperator(task_id="fail", python_callable=lambda **kwargs: "test")
ha.failed >> fail
passed = PythonOperator(task_id="passed", python_callable=lambda **kwargs: "test")
ha.passed >> passed
done = PythonOperator(task_id="done", python_callable=lambda **kwargs: "test")
ha.done >> done
This produces a DAG with the following topology:
This DAG exhibits cool behavior. If a check fails or the interval elapses, the DAG will re-trigger itself. If the check passes, the DAG will finish. This allows the one to build "always-on" DAGs without having individual long blocking tasks.
This library is used to build airflow-supervisor, which uses supervisor as a process-monitor while checking and restarting jobs via airflow-ha
.
License
This software is licensed under the Apache 2.0 license. See the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file airflow_ha-0.1.0.tar.gz
.
File metadata
- Download URL: airflow_ha-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a4b9b7434c0f36df8c8abbbaaa5b1a3f13524b4c435661706363030494a861e |
|
MD5 | 8f66529065a2f93b901e508393d7dee8 |
|
BLAKE2b-256 | 6aeab947188e21569f0880eb971ec75b7a6b388e98f341b8b462a6bd6f556c5c |
File details
Details for the file airflow_ha-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: airflow_ha-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eacf1af9f3bbb5ae73a90fe881cde20a83c757323121c57f4c4f75e509dd319 |
|
MD5 | 5812703f7b528f2f4b547b0d8e3c8b43 |
|
BLAKE2b-256 | 69e432735ea77382e12f62df8c50f26d207a87139ebd6f033f1b7ea7cb63ccc5 |