josh-fell commented on code in PR #30227:
URL: https://github.com/apache/airflow/pull/30227#discussion_r1150002691


##########
airflow/providers/dbt/cloud/sensors/dbt.py:
##########
@@ -68,6 +87,38 @@ def poke(self, context: Context) -> bool:
 
         return job_run_status == DbtCloudJobRunStatus.SUCCESS.value
 
+    def execute(self, context: Context) -> None:
+        """
+        Defers to Trigger class to poll for state of the job run until
+        it reaches a failure state or success state
+        """
+        if not self.deferrable:
+            super().execute(context)
+        else:
+            end_time = time.time() + self.timeout
+            self.defer(
+                timeout=self.execution_timeout,
+                trigger=DbtCloudRunJobTrigger(
+                    run_id=self.run_id,
+                    conn_id=self.dbt_cloud_conn_id,
+                    account_id=self.account_id,
+                    poll_interval=self.poke_interval,
+                    end_time=end_time,
+                ),
+                method_name="execute_complete",
+            )
+
+    def execute_complete(self, context: Context, event: dict[str, Any]) -> int:
+        """
+        Callback for when the trigger fires - returns immediately.
+        Relies on trigger to throw an exception, otherwise it assumes 
execution was
+        successful.
+        """
+        if event["status"] in ["error", "cancelled"]:
+            raise AirflowException("Error in dbt: " + event["message"])
+        self.log.info(event["message"])
+        return int(event["run_id"])
+
 
 class DbtCloudJobRunAsyncSensor(DbtCloudJobRunSensor):
     """

Review Comment:
   Let's replace the docstring for DbtCloudJobRunAsyncSensor with a deprecation 
note. This way it's plainly obvious in the Python API docs that this class is 
deprecated. Otherwise, users won't find out until the use the sensor in their 
DAG, run it, and _maybe_ look at the logs to notice. [Here is an 
example](https://github.com/apache/airflow/blob/47cf233ccd612a68bea1ad3898f06b91c63c1964/airflow/providers/amazon/aws/operators/lambda_function.py#L200).



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