How to work correctly airflow schedule_interval

前端 未结 5 1085
迷失自我
迷失自我 2021-01-04 13:00

I want to try to use Airflow instead of Cron. But schedule_interval doesn\'t work as I expected.

I wrote the python code like below.
And in my understanding, Air

5条回答
  •  死守一世寂寞
    2021-01-04 13:14

    Try this:

    # -*- coding: utf-8 -*-
    from __future__ import absolute_import, unicode_literals
    import os
    from airflow.operators import BashOperator
    from airflow.models import DAG
    from datetime import datetime, timedelta
    
    args = {
        'owner': 'airflow',
        'depends_on_past': False,
        'start_date': datetime(2016, 3, 29),
    }
    
    dag = DAG(
        dag_id='notice_slack',
        default_args=args,
        schedule_interval="15 08 * * *",
        dagrun_timeout=timedelta(minutes=1))
    
    # cmd file name
    CMD = 'bash /tmp/notice_slack.sh'
    
    run_this = BashOperator(
        task_id='run_transport', bash_command=CMD, dag=dag)
    

    start_date (datetime) – The start_date for the task, determines the execution_date for the first task instance. The best practice is to have the start_date rounded to your DAG’s schedule_interval.

    schedule_interval (datetime.timedelta or dateutil.relativedelta.relativedelta or str that acts as a cron expression) – Defines how often that DAG runs, this timedelta object gets added to your latest task instance’s execution_date to figure out the next schedule.

    Simply configuring the schedule_interval and bash_command as the same in your cron setting is okay.

提交回复
热议问题