dejii commented on code in PR #56400:
URL: https://github.com/apache/airflow/pull/56400#discussion_r2405285213


##########
providers/google/src/airflow/providers/google/cloud/triggers/pubsub.py:
##########
@@ -86,26 +86,22 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
         )
 
     async def run(self) -> AsyncIterator[TriggerEvent]:
-        try:
-            while True:
-                if pulled_messages := await self.hook.pull(
-                    project_id=self.project_id,
-                    subscription=self.subscription,
-                    max_messages=self.max_messages,
-                    return_immediately=True,
-                ):
-                    if self.ack_messages:
-                        await self.message_acknowledgement(pulled_messages)
+        while True:
+            if pulled_messages := await self.hook.pull(
+                project_id=self.project_id,
+                subscription=self.subscription,
+                max_messages=self.max_messages,
+                return_immediately=True,
+            ):
+                if self.ack_messages:
+                    await self.message_acknowledgement(pulled_messages)
 
-                    messages_json = [ReceivedMessage.to_dict(m) for m in 
pulled_messages]
+                messages_json = [ReceivedMessage.to_dict(m) for m in 
pulled_messages]
 
-                    yield TriggerEvent({"status": "success", "message": 
messages_json})
-                    return
-                self.log.info("Sleeping for %s seconds.", self.poke_interval)
-                await asyncio.sleep(self.poke_interval)
-        except Exception as e:
-            yield TriggerEvent({"status": "error", "message": str(e)})
-            return
+                yield TriggerEvent({"status": "success", "message": 
messages_json})
+                break

Review Comment:
   It doesn't affect the behaviour functionally, it's just more consistent with 
how other polling triggers are written – poll until condition met, then break 
out of the loop. See 
[SqsSensorTrigger](https://github.com/apache/airflow/blob/3a93f9b075b55fc3f657288e140cbdf46d92c56d/providers/amazon/src/airflow/providers/amazon/aws/triggers/sqs.py#L219)
 and 
[AwaitMessageTrigger](https://github.com/apache/airflow/blob/3a93f9b075b55fc3f657288e140cbdf46d92c56d/providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py#L66).
   



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