airflow-systemd 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ from systemd_pydantic import *
2
+
3
+ from .airflow import *
4
+ from .config import *
5
+
6
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .local import Systemd
2
+
3
+ __all__ = ("Systemd",)
@@ -0,0 +1,245 @@
1
+ from logging import getLogger
2
+ from typing import TYPE_CHECKING, Any, Literal
3
+
4
+ from airflow_pydantic import Pool, fail, skip
5
+ from systemd_pydantic import SystemdClient
6
+ from systemd_pydantic.convenience import (
7
+ SystemdTaskStep,
8
+ check_services,
9
+ remove_systemd_config,
10
+ restart_services,
11
+ start_services,
12
+ stop_services,
13
+ write_systemd_config,
14
+ )
15
+
16
+ from airflow_systemd.config.systemd import SystemdAirflowConfiguration
17
+
18
+ if TYPE_CHECKING:
19
+ from airflow_ha import CheckResult, HighAvailabilityOperator
20
+
21
+ DAG = Any
22
+ Operator = Any
23
+
24
+ __all__ = ("Systemd",)
25
+
26
+ _log = getLogger(__name__)
27
+ Step = SystemdTaskStep | Literal["force-kill"]
28
+
29
+
30
+ def _python_operator() -> Any:
31
+ from airflow_pydantic.airflow import PythonOperator
32
+
33
+ return PythonOperator
34
+
35
+
36
+ class Systemd:
37
+ """Airflow task group for a locally managed systemd job."""
38
+
39
+ def __init__(self, dag: "DAG", cfg: SystemdAirflowConfiguration | dict, **kwargs: Any):
40
+ if isinstance(cfg, dict):
41
+ cfg = SystemdAirflowConfiguration.model_validate(cfg)
42
+
43
+ self._cfg = cfg
44
+ self._pool = cfg.pool.pool if isinstance(cfg.pool, Pool) else cfg.pool
45
+ self._systemd_client = kwargs.pop("systemd_client", SystemdClient(cfg))
46
+ self._dag = dag
47
+
48
+ self.setup_dag()
49
+ self.initialize_tasks()
50
+
51
+ self.configure_systemd >> self.start_services >> self.check_services
52
+ self.check_services.retrigger_fail >> self.restart_services
53
+ self.check_services.stop_pass >> self.stop_services >> self.unconfigure_systemd
54
+
55
+ self._force_kill = self.get_step_operator("force-kill")
56
+
57
+ PythonOperator = _python_operator()
58
+
59
+ (
60
+ PythonOperator(
61
+ task_id=f"{self._dag.dag_id}-force-kill-dag",
62
+ python_callable=skip,
63
+ **self.get_base_operator_kwargs(),
64
+ )
65
+ >> self._force_kill
66
+ )
67
+
68
+ any_config_fail = PythonOperator(
69
+ task_id=f"{self._dag.dag_id}-check-config-failed",
70
+ python_callable=fail,
71
+ trigger_rule="one_failed",
72
+ **self.get_base_operator_kwargs(),
73
+ )
74
+ self.configure_systemd >> any_config_fail
75
+ self.start_services >> any_config_fail
76
+ self.stop_services >> any_config_fail
77
+ self.unconfigure_systemd >> any_config_fail
78
+
79
+ def setup_dag(self) -> None:
80
+ self._dag.catchup = False
81
+ self._dag.concurrency = 1
82
+ self._dag.max_active_tasks = 1
83
+ self._dag.max_active_runs = 1
84
+
85
+ def initialize_tasks(self) -> None:
86
+ PythonOperator = _python_operator()
87
+
88
+ self._check_services = self.get_step_operator("check-services")
89
+ self._configure_systemd = self.get_step_operator("configure-systemd")
90
+ self._start_services = self.get_step_operator("start-services")
91
+ if self._cfg.stop_on_exit:
92
+ self._stop_services = self.get_step_operator("stop-services")
93
+ if self._cfg.cleanup:
94
+ self._unconfigure_systemd = self.get_step_operator("unconfigure-systemd")
95
+ else:
96
+ self._unconfigure_systemd = PythonOperator(
97
+ task_id=f"{self._dag.dag_id}-unconfigure-systemd",
98
+ python_callable=skip,
99
+ **self.get_base_operator_kwargs(),
100
+ )
101
+ else:
102
+ self._stop_services = PythonOperator(
103
+ task_id=f"{self._dag.dag_id}-stop-services",
104
+ python_callable=skip,
105
+ **self.get_base_operator_kwargs(),
106
+ )
107
+ self._unconfigure_systemd = PythonOperator(
108
+ task_id=f"{self._dag.dag_id}-unconfigure-systemd",
109
+ python_callable=skip,
110
+ **self.get_base_operator_kwargs(),
111
+ )
112
+ self._restart_services = self.get_step_operator("restart-services")
113
+
114
+ @property
115
+ def configure_systemd(self) -> "Operator":
116
+ return self._configure_systemd
117
+
118
+ @property
119
+ def start_services(self) -> "Operator":
120
+ return self._start_services
121
+
122
+ @property
123
+ def check_services(self) -> "HighAvailabilityOperator":
124
+ return self._check_services
125
+
126
+ @property
127
+ def stop_services(self) -> "Operator":
128
+ return self._stop_services
129
+
130
+ @property
131
+ def restart_services(self) -> "Operator":
132
+ return self._restart_services
133
+
134
+ @property
135
+ def unconfigure_systemd(self) -> "Operator":
136
+ return self._unconfigure_systemd
137
+
138
+ @property
139
+ def systemd_client(self) -> SystemdClient:
140
+ return self._systemd_client
141
+
142
+ def get_base_operator_kwargs(self) -> dict[str, Any]:
143
+ return {"dag": self._dag, "pool": self._pool}
144
+
145
+ def get_step_kwargs(self, step: Step) -> dict[str, Any]:
146
+ cfg = self._cfg
147
+ if step == "configure-systemd":
148
+ return {
149
+ "python_callable": lambda **kwargs: (
150
+ self.check_services.check_end_conditions(**kwargs) is None
151
+ and write_systemd_config(cfg.model_dump_json(exclude_unset=True), _exit=False)
152
+ ),
153
+ "do_xcom_push": True,
154
+ }
155
+ if step == "start-services":
156
+
157
+ def _start_services(**kwargs: Any) -> bool:
158
+ if self.check_services.check_end_conditions(**kwargs) is not None:
159
+ return False
160
+ restart = cfg.restart_on_retrigger or (cfg.restart_on_initial and self.check_services.is_initial_run(**kwargs))
161
+ return start_services(cfg._pydantic_path, restart=restart, _exit=False)
162
+
163
+ return {
164
+ "python_callable": _start_services,
165
+ "do_xcom_push": True,
166
+ }
167
+ if step == "stop-services":
168
+ return {"python_callable": lambda: stop_services(cfg._pydantic_path, _exit=False), "do_xcom_push": True}
169
+ if step == "check-services":
170
+
171
+ def _check_services(systemd_cfg: SystemdAirflowConfiguration = cfg, **kwargs: Any) -> "CheckResult":
172
+ from airflow_ha import Action, Result
173
+
174
+ if check_services(systemd_cfg._pydantic_path, check_done=True, _exit=False):
175
+ return Result.PASS, Action.STOP
176
+ if check_services(systemd_cfg._pydantic_path, check_running=True, _exit=False):
177
+ return Result.PASS, Action.CONTINUE
178
+ if check_services(systemd_cfg._pydantic_path, _exit=False):
179
+ return Result.PASS, Action.CONTINUE
180
+ return Result.FAIL, Action.RETRIGGER
181
+
182
+ return {"python_callable": _check_services, "do_xcom_push": True}
183
+ if step == "restart-services":
184
+ return {"python_callable": lambda: restart_services(cfg._pydantic_path, _exit=False), "do_xcom_push": True}
185
+ if step == "unconfigure-systemd":
186
+ return {"python_callable": lambda: remove_systemd_config(cfg._pydantic_path, _exit=False), "do_xcom_push": True}
187
+ if step == "force-kill":
188
+ return {
189
+ "python_callable": lambda: all(info.stopped() for info in self.systemd_client.kill_services().values()),
190
+ "do_xcom_push": True,
191
+ }
192
+ raise NotImplementedError(f"Unknown step: {step}")
193
+
194
+ def get_step_operator(self, step: Step) -> "Operator":
195
+ from airflow_ha import HighAvailabilityOperator
196
+
197
+ PythonOperator = _python_operator()
198
+
199
+ if step == "check-services":
200
+ return HighAvailabilityOperator(
201
+ task_id=f"{self._dag.dag_id}-{step}",
202
+ poke_interval=self._cfg.check_interval.total_seconds(),
203
+ timeout=self._cfg.check_timeout.total_seconds(),
204
+ mode="poke",
205
+ runtime=self._cfg.runtime,
206
+ endtime=self._cfg.endtime,
207
+ maxretrigger=self._cfg.maxretrigger,
208
+ reference_date=self._cfg.reference_date,
209
+ **self.get_base_operator_kwargs(),
210
+ **self.get_step_kwargs(step),
211
+ )
212
+ return PythonOperator(
213
+ task_id=f"{self._dag.dag_id}-{step}",
214
+ **self.get_base_operator_kwargs(),
215
+ **self.get_step_kwargs(step),
216
+ )
217
+
218
+ def __lshift__(self, other: "Operator") -> "Operator":
219
+ self.configure_systemd << other
220
+ return self.unconfigure_systemd
221
+
222
+ def __rshift__(self, other: "Operator") -> "Operator":
223
+ self.unconfigure_systemd >> other
224
+ return other
225
+
226
+ def set_upstream(self, other: "Operator") -> None:
227
+ self.configure_systemd.set_upstream(other)
228
+
229
+ def set_downstream(self, other: "Operator") -> None:
230
+ self.unconfigure_systemd.set_downstream(other)
231
+
232
+ def update_relative(self, other: "Operator", upstream: bool = True, edge_modifier: Any = None) -> "Systemd":
233
+ if upstream:
234
+ self.configure_systemd.update_relative(other, upstream=True, edge_modifier=edge_modifier)
235
+ else:
236
+ self.unconfigure_systemd.update_relative(other, upstream=False, edge_modifier=edge_modifier)
237
+ return self
238
+
239
+ @property
240
+ def leaves(self):
241
+ return self.unconfigure_systemd.leaves
242
+
243
+ @property
244
+ def roots(self):
245
+ return self.configure_systemd.roots
@@ -0,0 +1,2 @@
1
+ from .systemd import *
2
+ from .task import *
@@ -0,0 +1,32 @@
1
+ from datetime import time, timedelta
2
+ from typing import Literal
3
+
4
+ from airflow_pydantic import Pool
5
+ from pydantic import Field
6
+ from systemd_pydantic import SystemdConvenienceConfiguration
7
+
8
+ __all__ = ("SystemdAirflowConfiguration", "load_airflow_config")
9
+
10
+
11
+ class SystemdAirflowConfiguration(SystemdConvenienceConfiguration):
12
+ """Systemd configuration for an Airflow-managed job."""
13
+
14
+ check_interval: timedelta = Field(default=timedelta(seconds=5), description="Interval between service status checks")
15
+ check_timeout: timedelta = Field(default=timedelta(hours=8), description="Timeout for service status checks")
16
+
17
+ runtime: timedelta | None = Field(default=None, description="Maximum runtime of the systemd job")
18
+ endtime: time | None = Field(default=None, description="End time of the systemd job")
19
+ maxretrigger: int | None = Field(default=None, description="Maximum number of service check retriggers")
20
+ reference_date: Literal["start_date", "logical_date", "data_interval_end"] = Field(
21
+ default="data_interval_end",
22
+ description="Date used to evaluate runtime and endtime",
23
+ )
24
+
25
+ pool: str | Pool | None = Field(default=None, description="Airflow pool for systemd tasks")
26
+ stop_on_exit: bool = Field(default=True, description="Stop services when the DAG finishes")
27
+ cleanup: bool = Field(default=True, description="Remove generated unit files when the DAG finishes")
28
+ restart_on_initial: bool = Field(default=False, description="Restart services on an initial Airflow run")
29
+ restart_on_retrigger: bool = Field(default=False, description="Restart services when airflow-ha retriggers the job")
30
+
31
+
32
+ load_airflow_config = SystemdAirflowConfiguration.load
@@ -0,0 +1,31 @@
1
+ from typing import Type
2
+
3
+ from airflow_pydantic import ImportPath, Task, TaskArgs
4
+ from pydantic import Field, field_validator
5
+
6
+ from .systemd import SystemdAirflowConfiguration
7
+
8
+ __all__ = ("SystemdOperator", "SystemdOperatorArgs", "SystemdTask", "SystemdTaskArgs")
9
+
10
+
11
+ class SystemdTaskArgs(TaskArgs):
12
+ cfg: SystemdAirflowConfiguration
13
+
14
+
15
+ SystemdOperatorArgs = SystemdTaskArgs
16
+
17
+
18
+ class SystemdTask(Task, SystemdTaskArgs):
19
+ operator: ImportPath = Field(default="airflow_systemd.Systemd", validate_default=True)
20
+
21
+ @field_validator("operator")
22
+ @classmethod
23
+ def validate_operator(cls, value: Type) -> Type:
24
+ from airflow_systemd.airflow import Systemd
25
+
26
+ if value is not Systemd:
27
+ raise ValueError(f"operator must be 'airflow_systemd.Systemd', got: {value}")
28
+ return value
29
+
30
+
31
+ SystemdOperator = SystemdTask
@@ -0,0 +1,20 @@
1
+ from pathlib import Path
2
+
3
+ import pytest
4
+
5
+ from airflow_systemd import ServiceConfiguration, ServiceUnitConfiguration, SystemdAirflowConfiguration
6
+
7
+
8
+ @pytest.fixture
9
+ def systemd_airflow_configuration(tmp_path: Path) -> SystemdAirflowConfiguration:
10
+ return SystemdAirflowConfiguration(
11
+ service={
12
+ "test": ServiceUnitConfiguration(
13
+ service=ServiceConfiguration(type="exec", exec_start="/bin/echo hello"),
14
+ )
15
+ },
16
+ unit_dir=tmp_path / "units",
17
+ working_dir=tmp_path / "state",
18
+ scope="user",
19
+ pool="test-pool",
20
+ )
@@ -0,0 +1,17 @@
1
+ from datetime import timedelta
2
+
3
+ from airflow_systemd import SystemdAirflowConfiguration
4
+
5
+
6
+ def test_airflow_configuration_defaults(systemd_airflow_configuration: SystemdAirflowConfiguration):
7
+ assert systemd_airflow_configuration.check_interval == timedelta(seconds=5)
8
+ assert systemd_airflow_configuration.check_timeout == timedelta(hours=8)
9
+ assert systemd_airflow_configuration.stop_on_exit is True
10
+ assert systemd_airflow_configuration.cleanup is True
11
+
12
+
13
+ def test_airflow_configuration_roundtrip(systemd_airflow_configuration: SystemdAirflowConfiguration):
14
+ value = SystemdAirflowConfiguration.model_validate_json(systemd_airflow_configuration.model_dump_json())
15
+
16
+ assert value == systemd_airflow_configuration
17
+ assert value._pydantic_path == systemd_airflow_configuration._pydantic_path
@@ -0,0 +1,130 @@
1
+ from typing import Any
2
+ from unittest.mock import Mock, patch
3
+
4
+ import pytest
5
+ from airflow_pydantic import airflow as airflow_compat
6
+ from airflow_pydantic.migration import _airflow_3
7
+
8
+ from airflow_systemd import SystemdAirflowConfiguration
9
+
10
+ DAG: Any = airflow_compat.DAG
11
+
12
+
13
+ @pytest.mark.skipif(_airflow_3() is None, reason="Airflow not installed")
14
+ class TestSystemd:
15
+ @staticmethod
16
+ def create_systemd(systemd_airflow_configuration: SystemdAirflowConfiguration, dag_id: str = "systemd-callbacks"):
17
+ from airflow_systemd import Systemd
18
+
19
+ return Systemd(dag=DAG(dag_id=dag_id, schedule=None), cfg=systemd_airflow_configuration)
20
+
21
+ def test_task_graph(self, systemd_airflow_configuration: SystemdAirflowConfiguration):
22
+ from airflow_systemd import Systemd
23
+
24
+ dag = DAG(dag_id="systemd-test", default_args={}, schedule=None, params={})
25
+ systemd = Systemd(dag=dag, cfg=systemd_airflow_configuration)
26
+
27
+ assert systemd.configure_systemd in dag.tasks
28
+ assert systemd.start_services in dag.tasks
29
+ assert systemd.check_services in dag.tasks
30
+ assert systemd.restart_services in dag.tasks
31
+ assert systemd.stop_services in dag.tasks
32
+ assert systemd.unconfigure_systemd in dag.tasks
33
+ assert dag.catchup is False
34
+ assert dag.max_active_tasks == 1
35
+ assert dag.max_active_runs == 1
36
+
37
+ @pytest.mark.parametrize(("stop_on_exit", "cleanup"), [(False, False), (True, False)])
38
+ def test_optional_cleanup(
39
+ self,
40
+ systemd_airflow_configuration: SystemdAirflowConfiguration,
41
+ stop_on_exit: bool,
42
+ cleanup: bool,
43
+ ):
44
+ from airflow_systemd import Systemd
45
+
46
+ cfg = systemd_airflow_configuration.model_copy(update={"stop_on_exit": stop_on_exit, "cleanup": cleanup})
47
+ dag = DAG(dag_id=f"systemd-cleanup-{stop_on_exit}-{cleanup}", schedule=None)
48
+ systemd = Systemd(dag=dag, cfg=cfg)
49
+
50
+ assert systemd.stop_services is not None
51
+ assert systemd.unconfigure_systemd is not None
52
+
53
+ def test_dict_configuration(self, systemd_airflow_configuration: SystemdAirflowConfiguration):
54
+ from airflow_systemd import Systemd
55
+
56
+ dag = DAG(dag_id="systemd-dict", schedule=None)
57
+ systemd = Systemd(dag=dag, cfg=systemd_airflow_configuration.model_dump())
58
+
59
+ assert systemd._cfg == systemd_airflow_configuration
60
+
61
+ def test_lifecycle_callbacks(self, systemd_airflow_configuration: SystemdAirflowConfiguration):
62
+ from airflow_ha import Action, Result
63
+
64
+ systemd = self.create_systemd(systemd_airflow_configuration)
65
+ systemd.check_services._check_end_conditions = Mock(return_value=None)
66
+ systemd._cfg.restart_on_retrigger = True
67
+
68
+ with (
69
+ patch("airflow_systemd.airflow.local.write_systemd_config", return_value=True) as write,
70
+ patch("airflow_systemd.airflow.local.start_services", return_value=True) as start,
71
+ patch("airflow_systemd.airflow.local.stop_services", return_value=True) as stop,
72
+ patch("airflow_systemd.airflow.local.restart_services", return_value=True) as restart,
73
+ patch("airflow_systemd.airflow.local.remove_systemd_config", return_value=True) as remove,
74
+ ):
75
+ assert systemd.get_step_kwargs("configure-systemd")["python_callable"]() is True
76
+ assert systemd.get_step_kwargs("start-services")["python_callable"]() is True
77
+ assert systemd.get_step_kwargs("stop-services")["python_callable"]() is True
78
+ assert systemd.get_step_kwargs("restart-services")["python_callable"]() is True
79
+ assert systemd.get_step_kwargs("unconfigure-systemd")["python_callable"]() is True
80
+
81
+ write.assert_called_once()
82
+ start.assert_called_once_with(systemd._cfg._pydantic_path, restart=True, _exit=False)
83
+ stop.assert_called_once()
84
+ restart.assert_called_once()
85
+ remove.assert_called_once()
86
+
87
+ systemd.check_services._check_end_conditions.return_value = "done"
88
+ assert systemd.get_step_kwargs("start-services")["python_callable"]() is False
89
+
90
+ check = systemd.get_step_kwargs("check-services")["python_callable"]
91
+ with patch("airflow_systemd.airflow.local.check_services", side_effect=[True]):
92
+ assert check() == (Result.PASS, Action.STOP)
93
+ with patch("airflow_systemd.airflow.local.check_services", side_effect=[False, True]):
94
+ assert check() == (Result.PASS, Action.CONTINUE)
95
+ with patch("airflow_systemd.airflow.local.check_services", side_effect=[False, False, True]):
96
+ assert check() == (Result.PASS, Action.CONTINUE)
97
+ with patch("airflow_systemd.airflow.local.check_services", side_effect=[False, False, False]):
98
+ assert check() == (Result.FAIL, Action.RETRIGGER)
99
+
100
+ def test_force_kill(self, systemd_airflow_configuration: SystemdAirflowConfiguration):
101
+ info = Mock()
102
+ info.stopped.return_value = True
103
+ client = Mock()
104
+ client.kill_services.return_value = {"test.service": info}
105
+
106
+ from airflow_systemd import Systemd
107
+
108
+ systemd = Systemd(
109
+ dag=DAG(dag_id="systemd-force-kill", schedule=None),
110
+ cfg=systemd_airflow_configuration,
111
+ systemd_client=client,
112
+ )
113
+
114
+ assert systemd.systemd_client is client
115
+ assert systemd.get_step_kwargs("force-kill")["python_callable"]() is True
116
+
117
+ def test_chaining_helpers(self, systemd_airflow_configuration: SystemdAirflowConfiguration):
118
+ systemd = self.create_systemd(systemd_airflow_configuration, "systemd-chaining")
119
+ PythonOperator: Any = airflow_compat.PythonOperator
120
+ before = PythonOperator(task_id="before", python_callable=lambda: None, dag=systemd._dag)
121
+ after = PythonOperator(task_id="after", python_callable=lambda: None, dag=systemd._dag)
122
+
123
+ assert systemd << before is systemd.unconfigure_systemd
124
+ assert systemd >> after is after
125
+ systemd.set_upstream(before)
126
+ systemd.set_downstream(after)
127
+ assert systemd.update_relative(before) is systemd
128
+ assert systemd.update_relative(after, upstream=False) is systemd
129
+ assert systemd.roots
130
+ assert systemd.leaves
@@ -0,0 +1,34 @@
1
+ import pytest
2
+ from pydantic import ValidationError
3
+
4
+ from airflow_systemd import (
5
+ Systemd,
6
+ SystemdAirflowConfiguration,
7
+ SystemdOperator,
8
+ SystemdOperatorArgs,
9
+ SystemdTask,
10
+ SystemdTaskArgs,
11
+ )
12
+
13
+
14
+ def test_task_args(systemd_airflow_configuration: SystemdAirflowConfiguration):
15
+ args = SystemdTaskArgs(cfg=systemd_airflow_configuration)
16
+
17
+ assert args.cfg == systemd_airflow_configuration
18
+ assert SystemdOperatorArgs is SystemdTaskArgs
19
+
20
+
21
+ def test_task_default_operator(systemd_airflow_configuration: SystemdAirflowConfiguration):
22
+ task = SystemdTask(task_id="systemd-task", cfg=systemd_airflow_configuration)
23
+
24
+ assert task.operator is Systemd
25
+ assert SystemdOperator is SystemdTask
26
+
27
+
28
+ def test_task_rejects_another_operator(systemd_airflow_configuration: SystemdAirflowConfiguration):
29
+ with pytest.raises(ValidationError, match="operator must be"):
30
+ SystemdTask(
31
+ task_id="systemd-task",
32
+ cfg=systemd_airflow_configuration,
33
+ operator="airflow_systemd.SystemdTask",
34
+ )
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: airflow-systemd
3
+ Version: 0.1.0
4
+ Summary: Systemd operators and configuration for long-running tasks
5
+ Project-URL: Repository, https://github.com/airflow-laminar/airflow-systemd
6
+ Project-URL: Homepage, https://github.com/airflow-laminar/airflow-systemd
7
+ Author-email: the airflow-systemd authors <t.paine154@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: airflow-ha<1.7,>=1.4.1
21
+ Requires-Dist: airflow-pydantic<1.6,>=1.5.5
22
+ Requires-Dist: systemd-pydantic<0.2,>=0.1
23
+ Provides-Extra: airflow
24
+ Requires-Dist: apache-airflow-providers-ssh; extra == 'airflow'
25
+ Requires-Dist: apache-airflow-providers-standard; extra == 'airflow'
26
+ Requires-Dist: apache-airflow<3,>=2.8; extra == 'airflow'
27
+ Provides-Extra: airflow3
28
+ Requires-Dist: apache-airflow-providers-ssh; extra == 'airflow3'
29
+ Requires-Dist: apache-airflow-providers-standard; extra == 'airflow3'
30
+ Requires-Dist: apache-airflow<3.2,>=3; extra == 'airflow3'
31
+ Provides-Extra: develop
32
+ Requires-Dist: airflow-config>=0.1.2; extra == 'develop'
33
+ Requires-Dist: airflow-pydantic; extra == 'develop'
34
+ Requires-Dist: build; extra == 'develop'
35
+ Requires-Dist: bump-my-version; extra == 'develop'
36
+ Requires-Dist: check-dist; extra == 'develop'
37
+ Requires-Dist: codespell; extra == 'develop'
38
+ Requires-Dist: hatchling; extra == 'develop'
39
+ Requires-Dist: mdformat; extra == 'develop'
40
+ Requires-Dist: mdformat-tables>=1; extra == 'develop'
41
+ Requires-Dist: pytest; extra == 'develop'
42
+ Requires-Dist: pytest-cov; extra == 'develop'
43
+ Requires-Dist: ruff; extra == 'develop'
44
+ Requires-Dist: systemd-pydantic<0.2,>=0.1; extra == 'develop'
45
+ Requires-Dist: twine; extra == 'develop'
46
+ Requires-Dist: ty; extra == 'develop'
47
+ Requires-Dist: uv; extra == 'develop'
48
+ Requires-Dist: wheel; extra == 'develop'
49
+ Description-Content-Type: text/markdown
50
+
51
+ # airflow-systemd
52
+
53
+ Systemd operators and configuration for long-running tasks
54
+
55
+ [![Build Status](https://github.com/airflow-laminar/airflow-systemd/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/airflow-laminar/airflow-systemd/actions/workflows/build.yaml)
56
+ [![codecov](https://codecov.io/gh/airflow-laminar/airflow-systemd/branch/main/graph/badge.svg)](https://codecov.io/gh/airflow-laminar/airflow-systemd)
57
+ [![License](https://img.shields.io/github/license/airflow-laminar/airflow-systemd)](https://github.com/airflow-laminar/airflow-systemd)
58
+ [![PyPI](https://img.shields.io/pypi/v/airflow-systemd.svg)](https://pypi.python.org/pypi/airflow-systemd)
59
+
60
+ ## Overview
61
+
62
+ `airflow-systemd` mirrors `airflow-supervisor` for hosts managed by systemd. It turns a
63
+ `SystemdAirflowConfiguration` into an Airflow task lifecycle:
64
+
65
+ ```text
66
+ configure-systemd -> start-services -> check-services
67
+ | |
68
+ v v
69
+ restart-services stop-services -> unconfigure-systemd
70
+ ```
71
+
72
+ Airflow owns scheduling, so this integration runs service units directly rather than
73
+ starting systemd timer units. Timer models remain available through `systemd-pydantic`
74
+ for non-Airflow consumers.
75
+
76
+ ```python
77
+ from airflow import DAG
78
+ from airflow_systemd import ServiceConfiguration, ServiceUnitConfiguration, Systemd, SystemdAirflowConfiguration
79
+
80
+ dag = DAG(dag_id="long-running-job", schedule="@daily")
81
+ config = SystemdAirflowConfiguration(
82
+ service={
83
+ "long-running-job": ServiceUnitConfiguration(
84
+ service=ServiceConfiguration(type="exec", exec_start="/opt/jobs/run"),
85
+ )
86
+ },
87
+ scope="user",
88
+ )
89
+ Systemd(dag=dag, cfg=config)
90
+ ```
91
+
92
+ The local integration supports the same Airflow-specific controls as
93
+ `airflow-supervisor`: status interval and timeout, runtime/end-time limits, retrigger
94
+ limits, pools, optional restart behavior, stop-on-exit, and cleanup.
95
+
96
+ > [!NOTE]
97
+ > This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
@@ -0,0 +1,14 @@
1
+ airflow_systemd/__init__.py,sha256=u2uYJSDKSmzemPxrz4OpCDZAjRObxrwD9YYLlLrEx7c,100
2
+ airflow_systemd/airflow/__init__.py,sha256=KlJLB8A6p5UBTmW4eKKDsfJJagA_wuepncMSaBbCn0A,51
3
+ airflow_systemd/airflow/local.py,sha256=du8Zgm1FBSolos0iuTkhrd1hhcXm78FVyntQ43pqUnc,9170
4
+ airflow_systemd/config/__init__.py,sha256=ozSxE2f7AUO7qO8ZYe27P8iF4COc75VsItYdlkSq-nk,43
5
+ airflow_systemd/config/systemd.py,sha256=if_0ZqwkSLlIzcpOxyXNwmYVDp3k-ub75iqODUZY6fg,1704
6
+ airflow_systemd/config/task.py,sha256=_eCzcNmUmItiXrtR_l14jSJT6ekiJksgCQdzYpBWYFg,843
7
+ airflow_systemd/tests/conftest.py,sha256=js_MyXw-IckLWz265iAsILB1PMtX0d3mJ2ajs2mUSqY,594
8
+ airflow_systemd/tests/test_config.py,sha256=A8PJ9JGON6UtYqmTOSRYkTwZ5R9pRYR4A9rxx0fjSr4,811
9
+ airflow_systemd/tests/test_local.py,sha256=XNUES5hTPWj-09gPLZ688CMU89jxxgYy6YbHSgXY7sY,6217
10
+ airflow_systemd/tests/test_task.py,sha256=8ab6aeSDlPRyFXF5txIt7TrCW50710su22eItswHtzE,1052
11
+ airflow_systemd-0.1.0.dist-info/METADATA,sha256=EfrSj2kWkv-HyahSOFICZNB_uC_VIRhbGf0HRcilelE,4493
12
+ airflow_systemd-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
13
+ airflow_systemd-0.1.0.dist-info/licenses/LICENSE,sha256=-YGoOCaxwBBL4djlUIyh_lKK8JgE2g5svYa2VEpZUUs,11357
14
+ airflow_systemd-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 the airflow-systemd authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.