Airflow TaskFlow: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
=Overview=
=Overview=
=Programming Model=
=Programming Model=
Functions annotated with <code>@task</code> are executed when the corresponding [[Airflow_Concepts#Task_Instance|task instance]] is executed.
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
from airflow.decorators import dag, task
from airflow.decorators import dag, task
Line 25: Line 26:
     task_a() >> task_b()
     task_a() >> task_b()
</syntaxhighlight>
</syntaxhighlight>
If the function's first argument is <code>ti</code>, a reference to the corresponding  [[Airflow_Concepts#Task_Instance|task instance]] it will be passed with it.


=Context=
=Context=

Revision as of 02:55, 16 July 2022

External

Internal

Overview

Programming Model

Functions annotated with @task are executed when the corresponding task instance is executed.

from airflow.decorators import dag, task
from datetime import datetime


@dag(
    [...]
)
def some_dag():
    @task
    def task_a(ti=None):
        print(f"executing task A, task instance {ti}")

    @task
    def task_b(ti=None):
        print(f"executing task B, task instance {ti}")

    task_a() >> task_b()

If the function's first argument is ti, a reference to the corresponding task instance it will be passed with it.

Context

https://airflow.apache.org/docs/apache-airflow/stable/concepts/taskflow.html#context
https://airflow.apache.org/docs/apache-airflow/stable/templates-ref.html#templates-variables

Logging

https://airflow.apache.org/docs/apache-airflow/stable/concepts/taskflow.html#logging