airflowdirected-acyclic-graphsairflow-2.x

Default value of sla in airflow task


I am trying to use sla with Airflow DAG. But I am not able to get the default value of sla anywhere in documentation (When SLA is not checked).

task2 = PythonOperator(
    task_id = "task_2",
    sla = timedelta(seconds=VAL),
    python_callable = dela,
    pool = 'monitoring_jobs_pool',
    provide_context = True,
    dag=dag
)

I am creating multiple DAGs with tasks like these where sla values is dependent on a variable, and most of the times this value (of VAL) fetched by another piece of code is 0, where I don't want to monitor SLA but at other places, this will be some value like 20, 50 or any other value to monitor. What should I set the default value of sla to skip the SLA check. Also would using a very large value to accomplish the same thing will have any effect on airflow performance. With 0 I thought the SLA check would be skipped, however task is visible in SLA miss UI even with sla value defined as 0. It's not feasible for me to miss "sla" keyword if sla is zero. Would appreciate any answers/suggestions to solve this issue.


Solution

  • The default value for SLA is None (which is in the BaseOperator)

    Setting VAL to 0 should trigger an SLA straight away since it misses the SLA from the offset.

    You could implement something like:

    task2 = PythonOperator(
        task_id="task_2",
        sla=timedelta(seconds=VAL) if VAL > 0 else None,
        python_callable=dela,
        pool='monitoring_jobs_pool',
        provide_context=True,
        dag=dag
    )
    

    to skip the SLA if VAL is 0.