bkossakowska commented on code in PR #28618:
URL: https://github.com/apache/airflow/pull/28618#discussion_r1086545210


##########
airflow/providers/google/cloud/triggers/dataproc.py:
##########
@@ -84,3 +84,73 @@ async def run(self):
                     raise AirflowException(f"Dataproc job execution failed 
{self.job_id}")
             await asyncio.sleep(self.polling_interval_seconds)
         yield TriggerEvent({"job_id": self.job_id, "job_state": state})
+
+
+class DataprocWorkflowTrigger(BaseTrigger):
+    """
+    Trigger that periodically polls information from Dataproc API to verify 
status.
+    Implementation leverages asynchronous transport.
+    """
+
+    def __init__(
+        self,
+        template_name: str,
+        name: str,
+        region: str,
+        project_id: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        impersonation_chain: str | Sequence[str] | None = None,
+        delegate_to: str | None = None,
+        poll_interval: int = 5,
+    ):
+        super().__init__()
+        self.gcp_conn_id = gcp_conn_id
+        self.template_name = template_name
+        self.name = name
+        self.impersonation_chain = impersonation_chain
+        self.project_id = project_id
+        self.region = region
+        self.poll_interval = poll_interval
+        self.delegate_to = delegate_to
+        self.hook = DataprocAsyncHook(
+            delegate_to=self.delegate_to,
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.impersonation_chain,
+        )
+
+    def serialize(self):
+        return (
+            
"airflow.providers.google.cloud.triggers.dataproc.DataprocWorkflowTrigger",
+            {
+                "template_name": self.template_name,
+                "name": self.name,
+                "project_id": self.project_id,
+                "region": self.region,
+                "gcp_conn_id": self.gcp_conn_id,
+                "delegate_to": self.delegate_to,
+                "impersonation_chain": self.impersonation_chain,
+                "poll_interval": self.poll_interval,
+            },
+        )
+
+    async def run(self):
+        hook = DataprocAsyncHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.impersonation_chain,
+        )
+        while True:
+            operation = await hook.get_operation(
+                project_id=self.project_id, region=self.region, 
operation_name=self.name
+            )
+            if operation.done:
+                break
+            elif operation.error.message:
+                raise AirflowException(f"Workflow error: 
{operation.error.message}")

Review Comment:
   done



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