How do I check when my next Airflow DAG run has been scheduled for a specific dag?
Asked Answered
K

4

16

I have airflow set up and running with some DAGs scheduled for once a day "0 0 * * *".

I want to check when is the next time a specific dag has been scheduled to run, but I can't see where I can do that within the admin.

Katiekatina answered 7/9, 2018 at 2:50 Comment(0)
O
16

If you want you use the Airflow's CLI, there's next_execution option

Get the next execution datetime of a DAG.

airflow next_execution [-h] [-sd SUBDIR] dag_id

UPDATE-1

If you need to do it programmatically (within an Airflow task), you can refer to

@cli_utils.action_logging
def next_execution(args):
    """
    Returns the next execution datetime of a DAG at the command line.
    >>> airflow next_execution tutorial
    2018-08-31 10:38:00
    """
    dag = get_dag(args)

    if dag.is_paused:
        print("[INFO] Please be reminded this DAG is PAUSED now.")

    if dag.latest_execution_date:
        next_execution_dttm = dag.following_schedule(dag.latest_execution_date)

        if next_execution_dttm is None:
            print("[WARN] No following schedule can be found. " +
                  "This DAG may have schedule interval '@once' or `None`.")

        print(next_execution_dttm)
    else:
        print("[WARN] Only applicable when there is execution record found for the DAG.")
        print(None)

UPDATE-2

To get not just the next, but further execution_dates, refer to Airflow - how to get all the future run date

Overcharge answered 26/6, 2019 at 22:58 Comment(0)
B
9

In version 2.0.0 of airflow, on the command-line you can find the next execution with

airflow dags next-execution <dag_id>
Battlefield answered 2/1, 2021 at 21:9 Comment(0)
V
2

If you wanted to fetch this within airflow you can use the jinja {{ next_execution_date }} but if you just wanted to find out when your dag will run next you can add the interval with the last run

For example

from the below image

enter image description here

Schedule interval is 15 minutes and last run was at 2018-09-07 08:32 so next run will be exactly 15 mins later which is 2018-09-07 08:47

Villeneuve answered 7/9, 2018 at 9:0 Comment(0)
L
1

If you want to see that programmatically (tested with Airflow v2.2.4):

info = dag.next_dagrun_info(None)
info.run_after  # datetime.datetime(2022, 3, 9, 22, 0, tzinfo=Timezone('UTC'))

you can also have:

info.logical_date  # datetime.datetime(2022, 3, 8, 22, 0, tzinfo=Timezone('UTC'))
info.data_interval  # DataInterval(start=datetime.datetime(2022, 3, 8, 22, ...

Leannaleanne answered 8/3, 2022 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.