liveBook · Manning

Defer method

As explained in Data Pipelines with Apache Airflow, Second Edition

The defer method is an Airflow operator method that transfers waiting task execution to the triggerer.

Use the defer method when an Airflow task must wait for external data without keeping its execution logic on a worker. The worker transfers the waiting task to the triggerer, which monitors the condition and later returns execution to the worker. section 9.5.2

A deferred operator coordinates waiting and completion through these elements:

  • Set a timeout so prolonged waiting raises an exception and fails the task. section 9.5.2

Waiting for MovieLens ratings

A custom sensor calls self.defer(trigger=MovielensTrigger(...), method_name="execute_complete", timeout=self._timeout). After ratings appear, execute_complete logs that they are available; a downstream fetch task can then proceed.

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Explains call parameters, trigger handoff, completion callback, timeout, and execution sequence, but not trigger internals in full.
Examples
Demonstrates a custom MovieLens sensor waiting for ratings before a downstream fetch task runs.
What it assumes
Assumes familiarity with Airflow operators, tasks, workers, triggers, and Python methods.
What you can do after
Build deferrable operators that wait asynchronously and resume through a named completion callback.
How it connects
Connects defer method with deferrable sensors, triggers, triggerer, execute, execute_complete, and downstream tasks.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.