e-galan commented on code in PR #37693: URL: https://github.com/apache/airflow/pull/37693#discussion_r1557674106
########## airflow/providers/google/cloud/sensors/dataflow.py: ########## @@ -276,26 +371,72 @@ def poke(self, context: Context) -> bool: location=self.location, ) - return self.callback(result) + return result if self.callback is None else self.callback(result) + + def execute(self, context: Context) -> Any: + """Airflow runs this method on the worker and defers using the trigger.""" + if not self.deferrable: + super().execute(context) + else: + self.defer( + timeout=self.execution_timeout, + trigger=DataflowJobMessagesTrigger( + job_id=self.job_id, + project_id=self.project_id, + location=self.location, + gcp_conn_id=self.gcp_conn_id, + poll_sleep=self.poll_interval, + impersonation_chain=self.impersonation_chain, + fail_on_terminal_state=self.fail_on_terminal_state, + ), + method_name="execute_complete", + ) + + def execute_complete(self, context: Context, event: dict[str, str | list]) -> Any: + """ + Execute this method when the task resumes its execution on the worker after deferral. + + If the trigger returns an event with success status - passes the event result to the callback function. + Returns the event result if no callback function is provided. + + If the trigger returns an event with error status - raises an exception. + """ + if event["status"] == "success": + self.log.info(event["message"]) + return event["result"] if self.callback is None else self.callback(event["result"]) + if self.soft_fail: Review Comment: @Lee-W Could you explain this comment please? Is the `soft_fail` parameter getting removed from base sensor class? Also your suggestion is a bit different from a similarly looking comment in `poke()`: *# TODO: remove this if check when min_airflow_version is set to higher than 2.7.1* -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org