uranusjr commented on code in PR #38674:
URL: https://github.com/apache/airflow/pull/38674#discussion_r1577423825
##########
docs/apache-airflow/authoring-and-scheduling/deferring.rst:
##########
@@ -141,6 +141,60 @@ The ``self.defer`` call raises the ``TaskDeferred``
exception, so it can work an
``execution_timeout`` on operators is determined from the *total runtime*, not
individual executions between deferrals. This means that if
``execution_timeout`` is set, an operator can fail while it's deferred or while
it's running after a deferral, even if it's only been resumed for a few seconds.
+Triggering Deferral from Start
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you want to defer your task directly to the triggerer without going into
the worker, you can add the class level attributes ``start_trigger`` and
``_next_method`` to your deferrable operator.
+
+* ``start_trigger``: An instance of a trigger you want to defer to. It will be
serialized into the database.
+* ``next_method``: The method name on your operator that you want Airflow to
call when it resumes.
+
+
+This is particularly useful when deferring is the only thing the ``execute``
method does. Here's a basic refinement of the previous example.
+
+.. code-block:: python
+
+ from datetime import timedelta
+ from typing import Any
+
+ from airflow.sensors.base import BaseSensorOperator
+ from airflow.triggers.temporal import TimeDeltaTrigger
+ from airflow.utils.context import Context
+
+
+ class WaitOneHourSensor(BaseSensorOperator):
+ start_trigger = TimeDeltaTrigger(timedelta(hours=1))
+ next_method = "execute_complete"
+
+ def execute_complete(self, context: Context, event: dict[str, Any] |
None = None) -> None:
+ # We have no more work to do here. Mark as complete.
+ return
+
+``start_trigger`` and ``next_method`` can also be set at the instance level
for more flexible configuration.
+
+.. warning::
+ Dynamic task mapping is not supported when ``start_trigger`` and
``next_method`` are assigned in instance level.
Review Comment:
```suggestion
Dynamic task mapping is not supported when ``start_trigger`` and
``next_method`` are assigned at the instance level.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]