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.
Advertisement
Answer
If you want you use the Airflow
‘s CLI
, there’s next_execution
option
Get the next execution datetime of a DAG.
JavaScriptx21airflow next_execution [-h] [-sd SUBDIR] dag_id
2
UPDATE-1
If you need to do it programmatically (within an Airflow task
), you can refer to
next_execution(..)
function ofcli.py
- (now moved to
dag_next_execution(..)
function ofdag_command.py
inmaster
)
JavaScript124241@cli_utils.action_logging
2def next_execution(args):
3"""
4Returns the next execution datetime of a DAG at the command line.
5>>> airflow next_execution tutorial
62018-08-31 10:38:00
7"""
8dag = get_dag(args)
9
10if dag.is_paused:
11print("[INFO] Please be reminded this DAG is PAUSED now.")
12
13if dag.latest_execution_date:
14next_execution_dttm = dag.following_schedule(dag.latest_execution_date)
15
16if next_execution_dttm is None:
17print("[WARN] No following schedule can be found. " +
18"This DAG may have schedule interval '@once' or `None`.")
19
20print(next_execution_dttm)
21else:
22print("[WARN] Only applicable when there is execution record found for the DAG.")
23print(None)
24
UPDATE-2
To get not just the next, but further execution_date
s, refer to Airflow – how to get all the future run date