Jim Moriarty
Jim Moriarty

Reputation: 301

How to get dag status like running or success or failure

I want to know the status of dag whether it is running or failure or success. I am triggering dag through CL argument airflow trigger and after the execution of job, I want to know the status of the run. I couldn't find any way.

I tried airflow dag_state but it is giving none. What should I do if there are more than one runs in a day to get status of latest run through command line argument or through python code.

Upvotes: 9

Views: 34049

Answers (2)

Josh
Josh

Reputation: 1976

You can use list_dag_runs command with the CLI to list the dag runs for a given dag ID. The information returned includes the state of each run.

You can also retrieve the information via python code a few different ways. One such way that I've used in the past is the 'find' method in airflow.models.dagrun.DagRun

An example with python3 on how to get the state of dag_runs via DagRun.find():

dag_id = 'fake_dag_id'
dag_runs = DagRun.find(dag_id=dag_id)
for dag_run in dag_runs:
      print(dag_run.state)

Upvotes: 15

Dakshin Rajavel
Dakshin Rajavel

Reputation: 355

You can use the following CL

airflow dag_state dag_id execution_date

Example:

        airflow dag_state test_dag_id 2019-11-08T18:36:39.628099+00:00

In the above example:

test_dag_id is the actual dag
2019-11-08T18:36:39.628099+00:00 is the execution date. You can get this from airflow UI for your run.

Other option is to use airflow rest api plugin. This is better option. You can trigger a DAG and also check the status of the dag.

https://github.com/teamclairvoyant/airflow-rest-api-plugin

Upvotes: 2

Related Questions