I am trying to setup a DAG where a task is run every minute, and then another task is run on the 5th minute (right before the 1 minute task). It's really just testing, I am not planning to run jobs in such short intervals.
Visually, my DAG looks like this:
And the code itself like this:
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import BranchPythonOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2018, 10, 9)
}
now = datetime.now()
minute_check = now.minute % 5
dag = DAG(
dag_id='test3',
default_args=default_args,
schedule_interval='* * * * *',
dagrun_timeout=timedelta(minutes=5),
catchup=False,
max_active_runs=99
)
def check_minute():
if minute_check == 0:
return "branch_fiveminute"
else:
return "branch_minute"
branch_task = BranchPythonOperator(
task_id='branch_task',
python_callable=check_minute,
trigger_rule='all_done',
dag=dag)
branch_minute = BashOperator(
task_id='branch_minute',
bash_command='test1min.sh ',
trigger_rule='all_done',
dag=dag)
branch_fiveminute = BashOperator(
task_id='branch_fiveminute',
bash_command='test5min.sh ',
trigger_rule='all_done',
dag=dag)
branch_task.set_downstream(branch_minute)
branch_task.set_downstream(branch_fiveminute)
branch_fiveminute.set_downstream(branch_minute)
The problem i am getting is, that on the 5th minute, airflow skips the 1 minute task:
I have tried playing around with the trigger_rule settings without much success.
Any ideas whats wrong? I am using Airflow 1.10 if it matters.