sunank200 commented on code in PR #40084:
URL: https://github.com/apache/airflow/pull/40084#discussion_r1687953323


##########
docs/apache-airflow/authoring-and-scheduling/deferring.rst:
##########
@@ -253,6 +253,73 @@ These parameters can be mapped using the ``expand`` and 
``partial`` methods. Not
         trigger_kwargs=[{"moment": timedelta(hours=2)}, {"moment": 
timedelta(hours=2)}]
     )
 
+Exiting deferred task from Triggers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ .. versionadded:: 2.10.0
+
+If you want to exit your task directly from the triggerer without going into 
the worker, you can specific operator level attribute ``end_from_trigger`` with 
the attributes to your deferrable operator other discussed above.
+
+Triggers can have two options: they can either send execution back to the 
worker or end the task instance directly. If the trigger ends the task instance 
itself, the ``method_name`` does not matter and can be ``None``. Otherwise, 
provide the name of the ``method_name`` that should be used when resuming 
execution in the task.
+
+.. code-block:: python
+
+    class DateTimeSensorAsync(DateTimeSensor):
+        def __init__(self, end_from_trigger: bool = True, **kwargs) -> None:
+            super().__init__(**kwargs)
+            self.end_from_trigger = end_from_trigger
+
+        def execute(self, context: Context) -> NoReturn:
+            self.defer(
+                method_name="execute_complete",
+                trigger=DateTimeTrigger(
+                    moment=timezone.parse(self.target_time), 
end_from_trigger=self.end_from_trigger
+                ),
+            )
+
+        def execute_complete(self, context, event=None) -> None:
+            return None
+
+``TaskSuccessEvent`` and ``TaskFailureEvent`` are the two events that can be 
used to end the task instance directly. This marks the task with the state 
``task_instance_state`` and optionally pushes xcom if applicable. Here's an 
example of how to use these events:
+
+.. code-block:: python
+
+
+    class DateTimeTrigger(BaseTrigger):
+        def __init__(self, moment: datetime.datetime, *, end_from_trigger: 
bool = False):

Review Comment:
   I have changed the example completely now with `WaitFiveHourTrigger` and 
`WaitFiveHourSensorAsync`.



##########
docs/apache-airflow/authoring-and-scheduling/deferring.rst:
##########
@@ -253,6 +253,73 @@ These parameters can be mapped using the ``expand`` and 
``partial`` methods. Not
         trigger_kwargs=[{"moment": timedelta(hours=2)}, {"moment": 
timedelta(hours=2)}]
     )
 
+Exiting deferred task from Triggers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ .. versionadded:: 2.10.0
+
+If you want to exit your task directly from the triggerer without going into 
the worker, you can specific operator level attribute ``end_from_trigger`` with 
the attributes to your deferrable operator other discussed above.
+
+Triggers can have two options: they can either send execution back to the 
worker or end the task instance directly. If the trigger ends the task instance 
itself, the ``method_name`` does not matter and can be ``None``. Otherwise, 
provide the name of the ``method_name`` that should be used when resuming 
execution in the task.
+
+.. code-block:: python
+
+    class DateTimeSensorAsync(DateTimeSensor):
+        def __init__(self, end_from_trigger: bool = True, **kwargs) -> None:
+            super().__init__(**kwargs)
+            self.end_from_trigger = end_from_trigger
+
+        def execute(self, context: Context) -> NoReturn:
+            self.defer(
+                method_name="execute_complete",
+                trigger=DateTimeTrigger(
+                    moment=timezone.parse(self.target_time), 
end_from_trigger=self.end_from_trigger
+                ),
+            )
+
+        def execute_complete(self, context, event=None) -> None:
+            return None

Review Comment:
   I have changed the example completely now with `WaitFiveHourTrigger` and 
`WaitFiveHourSensorAsync`.



-- 
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]

Reply via email to