Create a airflow job to run only once

Hi,

Can you please let me know how to create a airflow job to run only once? Means will not be run second time.

Thanks

1 Like

There are some preset schedule available in airflow! You can find more information under the DAG runs section of the official airflow document. The one that will denote that a DAG is to be scheduled only once would be the @once macro.

It should look something similar to this instantiation of a DAG object

from airflow.models import DAG

dag = DAG(
    dag_id='my_dag',
    schedule_interval='@once'
)

Once a dagrun has been created, it will not create anymore regardless of the state of the dagrun.

2 Likes

Thank you @Alan for great help.