Lee-W commented on code in PR #30227:
URL: https://github.com/apache/airflow/pull/30227#discussion_r1150415262
##########
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:
I just changed it. Thanks for your suggestion!
--
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]