airflow-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From siddharth anand <>
Subject Reminder : LatestOnlyOperator
Date Fri, 17 Mar 2017 23:33:11 GMT
With the Apache Airflow 1.8 release imminent, you may want to try out the


If you want your DAG to only run on the most recent scheduled slot,
regardless of backlog, this operator will skip running downstream tasks for
all DAG Runs prior to the current time slot.

For example, I might have a DAG that takes a DB snapshot once a day. It
might be that I paused that DAG for 2 weeks or that I had set the start
date to a fixed data 2 weeks in the past. When I enable my DAG, I don't
want it to run 14 days' worth of snapshots for the current state of the DB
-- that's unnecessary work.

The LatestOnlyOperator avoids that work.

With it, you can simply use
latest_only = LatestOnlyOperator(task_id='latest_only', dag=dag)

instead of
def skip_to_current_job(ds, **kwargs):
    now =
    left_window = kwargs['dag'].following_schedule(kwargs['execution_date'])
    right_window = kwargs['dag'].following_schedule(left_window)'Left Window {}, Now {}, Right Window
    if not now <= right_window:'Not latest execution, skipping downstream.')
        return False
    return True

short_circuit = ShortCircuitOperator(
  task_id         = 'short_circuit_if_not_current_job',
  provide_context = True,
  python_callable = skip_to_current_job,
  dag             = dag


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message