Defining tasks and dependencies
Apache Airflow represents a workflow as a Dag. A Dag brings together the information needed for execution: tasks, the dependencies between tasks, and when the workflow runs are among them. Callback actions to perform when the workflow completes and other run parameters can also be part of a Dag.
The term Dag used by Airflow comes from the mathematical concept of a directed acyclic graph. In Airflow, the meaning of the term is not limited to the data structure. A Dag also covers the order and the conditions under which tasks are executed. Tasks, in turn, are separate units of work that run on a worker.
A task can have upstream tasks that come before it and downstream tasks that depend on it. In Airflow, these relationships form the Dag structure. By default, a task waits until all of the upstream tasks it depends on have succeeded. Different execution conditions can be defined with trigger_rule.
In Airflow, tasks usually take the form of an Operator, a Sensor, or a TaskFlow function. An Operator is a predefined task. A Sensor is a special type of Operator that waits for an external event to occur. A TaskFlow function defined with @task packages a custom Python function as a task.
Expressing dependencies
In Airflow, individual task dependencies are expressed with the >> and << operators or with the set_upstream and set_downstream methods. Multiple tasks can be defined after a task. This way, paths that depend on the same task are shown separately in the Dag.
To make a list of tasks depend on the tasks in another list, cross_downstream is used. To chain tasks together, chain is used. Airflow also notes that chain can set up pairwise dependencies between lists of the same length. These pairwise relationships differ from the cross dependencies created with cross_downstream.
In Argo Workflows, a dag template defines tasks as a dependency graph. For each task, the other tasks that must complete before it starts are specified. Tasks with no dependencies run immediately. In Argo's example, A runs first; when A completes, B and C run in parallel. D runs after both B and C have completed.
In this example, dependencies are kept in the dependencies field. The field value is [A] for B and C, and [B, C] for D. The template each task uses is specified with the template field. Task names are given in the name field.
In Argo, the steps template also organizes the execution of tasks. The structure consists of nested lists: the outer lists run sequentially, and the steps in the inner lists run in parallel. when can be used to run a step conditionally. A Synchronization feature is available for running the steps in the inner lists sequentially.
The scope of a run
In Airflow, a Dag can be triggered manually or through the API. If a schedule is defined in the Dag, it can also run according to that schedule. Defining a schedule for a Dag is not mandatory. Each run creates a separate Dag instance, which Airflow calls a Dag Run.
Dag Runs of the same Dag can run in parallel. Each Dag Run has a data interval value. This interval indicates the data period the tasks will work on. When a Dag Run is created, Task Instances are also created for the tasks in the Dag.
For a Dag to run, each Operator or Task must be assigned to a Dag. Airflow can compute this assignment when an Operator is defined inside a with DAG block or inside a @dag decorator. The assignment can also be computed when an Operator is placed on the upstream or downstream side of another Operator that is already assigned to a Dag. In other cases, the Dag is passed to the Operator with dag=.
When creating a Dag in Airflow, default_args can be provided. These arguments are automatically applied to the Operators in the Dag. For example, the retries value can be defined in these shared arguments instead of being specified separately for each Operator.
When loading Dags from Python files, Airflow picks up the top-level Dag objects in the file. A Dag object created inside a function and not present at the top level is not loaded. For the Dag produced by a function defined with @dag to be loaded, the function is called and the result is assigned to a top-level object.
In Argo Workflows, a Workflow both defines the workflow to be executed and holds the workflow's state. The execution definition is in the Workflow.spec field. At the core of this structure are a templates list and an entrypoint. The entrypoint determines the first template to run.
A Container template in Argo schedules the running of a container. A Script template adds the source field to the Container structure; the script defined in this field is saved to a file and executed. In both template types, standard output is passed to an Argo variable.
Branching and task conditions
In Airflow, branching makes it possible to follow one or more paths instead of running all of the dependent tasks. A function marked with @task.branch returns a task ID or a list of task IDs. The specified paths are followed and the others are skipped. If the function returns None, all downstream tasks are skipped.