A custom Airflow sensor to check if the current time is within a specific interval and time zone.
Project description
TimeIntervalSensor for Apache Airflow
TimeIntervalSensor is a custom sensor for Apache Airflow that checks if the current time falls within a specified interval, while also supporting time zones. It's designed to enhance time-sensitive workflows by ensuring that tasks only proceed during the defined time window, making it ideal for business hours, processing windows, and global workflows that rely on multiple time zones.
Features
- Time Interval Validation: Define a start and end time, and the sensor will only allow tasks to proceed if the current time falls within that range.
- Time Zone Support: The sensor can handle multiple time zones, ensuring that tasks are executed at the correct time, regardless of the region.
- Seamless Airflow Integration: Easily integrate the
TimeIntervalSensorinto your DAGs, just like any other Airflow operator or sensor.
Installation
You can install the package using pip:
pip install time-interval-sensor
Quick Start
Here is a simple example of how to use TimeIntervalSensor in your Airflow DAGs:
from airflow import DAG
from sensors.time_interval_sensor import TimeIntervalSensor
from datetime import datetime, time
default_args = {
'start_date': datetime(2024, 1, 1),
}
with DAG(dag_id='time_interval_sensor_dag', default_args=default_args, schedule_interval=None) as dag:
time_check = TimeIntervalSensor(
task_id='check_time_interval',
start_time=time(9, 0), # 9:00 AM
end_time=time(17, 0), # 5:00 PM
time_zone='America/New_York',
timeout=30, # Set timeout to 30 seconds
mode='reschedule', # Use 'reschedule' mode for the sensor
poke_interval=5 # Poke every 5 seconds
)
Use Cases
- Business Hours Execution: Ensure that certain tasks are only run during specific working hours (e.g., 9 AM to 5 PM).
- Global Time Zone Coordination: Trigger tasks at the correct time in different time zones, making it easy to manage distributed workflows.
- Time-Sensitive Processing: Use the sensor to define a time window for batch jobs or data processing that depends on specific hours.
Parameters
- start_time: Start of the time interval (Python
timeobject). - end_time: End of the time interval (Python
timeobject). - time_zone: The name of the time zone to be used (default: 'UTC').
- timeout: Seconds after which task sensor will fail the task if not within time interval
- mode: (Optional) If you'd like to free up the worker slot between checks, you can set the mode to reschedule
- poke_interval: (Optional) If you want to test repeatedly with the given frequency in seconds
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file time_interval_sensor-0.1.5.tar.gz.
File metadata
- Download URL: time_interval_sensor-0.1.5.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9419c4703b9d73cec97ed7acd8b9ccbd4c9e6cbb70308882bc5b95c1049f09e4
|
|
| MD5 |
f76dd85674a0579a2d480a9ea7e00019
|
|
| BLAKE2b-256 |
3b06b7e14dcced347f8ee845478336bb5cf370175ea1c1190f0d6fa1d4d9397e
|
File details
Details for the file time_interval_sensor-0.1.5-py3-none-any.whl.
File metadata
- Download URL: time_interval_sensor-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b5cd52e86afbe1bcd2f8b6bc12fbb4064c1093c50a7fc8c844b42e1de7afddb
|
|
| MD5 |
1a8092103bc6106f2c16e34d686f258a
|
|
| BLAKE2b-256 |
35f9db089f924a70c2bba874ecd8f743d40da15e1621e07ac1ae8cab356624ae
|