Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to schedule the airflow DAG to run just after the end of the previous running DAG?

I have a simple DAG with 2 PythonOperator and schedule interval for 2 minutes:

with DAG(dag_id='example_cron', schedule_interval='*/2 * * * *', start_date=days_ago(2)) as dag:

    def task1_func(ti):
        print("start task 1")
        time.sleep(random.randint(0, 70))
        print("end task 1")

    def task2_func(ti):
        print("start task 2")
        time.sleep(random.randint(0, 70))
        print("end task 2")


    task1  = PythonOperator(task_id='task1', python_callable=task1_func, provide_context=True)
    task2  = PythonOperator(task_id='task2', python_callable=task2_func, provide_context=True)

task1 >> task2
  • The DAG can run more than 2 minutes and this means that more than one DAG may run in parallel.

How can I configure the DAG to run just if the previous run has finished ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You simply need to add max_active_runs=1 to your DAG object.

with DAG(..., max_active_runs=1) as dag:

Not part of your question but please note that days_ago(2) is deprecated and in any case you should not use dynamic dates for start_date (see docs)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading