Skip to main content

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 TimeIntervalSensor into 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���s 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 time object).
  • end_time: End of the time interval (Python time object).
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

time_interval_sensor-0.1.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

time_interval_sensor-0.1.4-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file time_interval_sensor-0.1.4.tar.gz.

File metadata

  • Download URL: time_interval_sensor-0.1.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for time_interval_sensor-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8acf78544169624be12799e8105e3df1f26512ec8dc5f9fd6cc10689041d03f2
MD5 a63ef2e4f9cbe1aaf54bdccc81beadf0
BLAKE2b-256 ed178d156617821be468bf13e3be54817901e53ef2b84c51fc22d94c08d1e829

See more details on using hashes here.

File details

Details for the file time_interval_sensor-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for time_interval_sensor-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 412a098ddb0405887ff008d9b0d5f378b3d71d862d08fe070ead73500f640533
MD5 e1edf0843cd559ab38b937e8185dd377
BLAKE2b-256 96727fa1a22630abb3bb206d239b2ba56a03b6940fc5fae3955d956a1d402080

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page