SameerMesiah97 commented on code in PR #64051:
URL: https://github.com/apache/airflow/pull/64051#discussion_r3142050747


##########
providers/airbyte/src/airflow/providers/airbyte/triggers/airbyte.py:
##########
@@ -80,32 +99,41 @@ async def run(self) -> AsyncIterator[TriggerEvent]:
                         }
                     )
                     return
-                await asyncio.sleep(self.poll_interval)
-            job_run_status = hook.get_job_status(self.job_id)
-            if job_run_status == JobStatusEnum.SUCCEEDED:
-                yield TriggerEvent(
-                    {
-                        "status": "success",
-                        "message": f"Job run {self.job_id} has completed 
successfully.",
-                        "job_id": self.job_id,
-                    }
-                )
-            elif job_run_status == JobStatusEnum.CANCELLED:
-                yield TriggerEvent(
-                    {
-                        "status": "cancelled",
-                        "message": f"Job run {self.job_id} has been 
cancelled.",
-                        "job_id": self.job_id,
-                    }
-                )
-            else:
-                yield TriggerEvent(
-                    {
-                        "status": "error",
-                        "message": f"Job run {self.job_id} has failed.",
-                        "job_id": self.job_id,
-                    }
-                )
+
+                job_run_status = hook.get_job_status(self.job_id)
+
+                if job_run_status in (
+                    JobStatusEnum.RUNNING,
+                    JobStatusEnum.PENDING,
+                    JobStatusEnum.INCOMPLETE,
+                ):
+                    await asyncio.sleep(self.poll_interval)
+                    continue
+
+                if job_run_status == JobStatusEnum.SUCCEEDED:
+                    yield TriggerEvent(
+                        {
+                            "status": "success",
+                            "message": f"Job run {self.job_id} has completed 
successfully.",
+                            "job_id": self.job_id,
+                        }
+                    )
+                elif job_run_status == JobStatusEnum.CANCELLED:
+                    yield TriggerEvent(
+                        {
+                            "status": "cancelled",
+                            "message": f"Job run {self.job_id} has been 
cancelled.",
+                            "job_id": self.job_id,
+                        }
+                    )
+                else:
+                    yield TriggerEvent(
+                        {
+                            "status": "error",
+                            "message": f"Job run {self.job_id} has failed.",
+                            "job_id": self.job_id,
+                        }
+                    )

Review Comment:
   This is a serious issue that should have been caught by my self-review 
process. My apologies. 
   
   I have added a `return` after each yield (there were 4 with missing `return` 
statements including the one under `Exception`). Additionally, the tests have 
been adjusted to generate the events in the manner you suggested and an 
additional test has been added to guard against this specific bug i.e. infinite 
loop. 



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