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.3.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.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: time_interval_sensor-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 1f211acc747da7aaad7228abbcfcd0a955f8af9f0b64b4db15c203707775aa28
MD5 e30b5179cf75ecce38e2dfb4608ee7d8
BLAKE2b-256 1dc26d0e545250f41eec1b636a44c3f9ee872615185483824c065c03acc585a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for time_interval_sensor-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e3d82072ac271295059d0f71250656afaf70565033aa1e024b5246e8420c2285
MD5 c5722ddefaf75ebbac821f2d6c936104
BLAKE2b-256 a852c4f203b3b41db22726ffaf792c2ece11f228d659c100995c203e082e539e

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