@@ -72,31 +72,29 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
7272 )
7373
7474 async def run (self ) -> AsyncIterator [TriggerEvent ]: # type: ignore[override]
75+ """Gets current job execution status and yields a TriggerEvent."""
7576 """Gets current job execution status and yields a TriggerEvent."""
7677 hook = self ._get_async_hook ()
7778 while True :
7879 try :
79- # Poll for job execution status
80- response_from_hook = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
81- self .log .debug ("Response from hook: %s" , response_from_hook )
82-
83- if response_from_hook == "success" :
80+ job_status = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
81+ if job_status == "success" :
8482 yield TriggerEvent (
8583 {
8684 "job_id" : self .job_id ,
87- "status" : "success" ,
85+ "status" : job_status ,
8886 "message" : "Job completed" ,
8987 }
9088 )
9189 return
92- elif response_from_hook == "pending" :
93- self .log .info ("Query is still running..." )
94- self .log .info ("Sleeping for %s seconds." , self .poll_interval )
95- await asyncio .sleep (self .poll_interval )
96- else :
97- yield TriggerEvent ({"status" : "error" , "message" : response_from_hook })
90+ elif job_status == "error" :
91+ yield TriggerEvent ({"status" : "error" })
9892 return
99-
93+ else :
94+ self .log .info (
95+ "Bigquery job status is %s. Sleeping for %s seconds." , job_status , self .poll_interval
96+ )
97+ await asyncio .sleep (self .poll_interval )
10098 except Exception as e :
10199 self .log .exception ("Exception occurred while checking for query completion" )
102100 yield TriggerEvent ({"status" : "error" , "message" : str (e )})
@@ -129,8 +127,8 @@ async def run(self) -> AsyncIterator[TriggerEvent]: # type: ignore[override]
129127 while True :
130128 try :
131129 # Poll for job execution status
132- response_from_hook = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
133- if response_from_hook == "success" :
130+ job_status = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
131+ if job_status == "success" :
134132 query_results = await hook .get_job_output (job_id = self .job_id , project_id = self .project_id )
135133
136134 records = hook .get_records (query_results )
@@ -154,14 +152,14 @@ async def run(self) -> AsyncIterator[TriggerEvent]: # type: ignore[override]
154152 }
155153 )
156154 return
157-
158- elif response_from_hook == "pending" :
159- self .log .info ("Query is still running..." )
160- self .log .info ("Sleeping for %s seconds." , self .poll_interval )
161- await asyncio .sleep (self .poll_interval )
162- else :
163- yield TriggerEvent ({"status" : "error" , "message" : response_from_hook })
155+ elif job_status == "error" :
156+ yield TriggerEvent ({"status" : "error" , "message" : job_status })
164157 return
158+ else :
159+ self .log .info (
160+ "Bigquery job status is %s. Sleeping for %s seconds." , job_status , self .poll_interval
161+ )
162+ await asyncio .sleep (self .poll_interval )
165163 except Exception as e :
166164 self .log .exception ("Exception occurred while checking for query completion" )
167165 yield TriggerEvent ({"status" : "error" , "message" : str (e )})
@@ -201,26 +199,27 @@ async def run(self) -> AsyncIterator[TriggerEvent]: # type: ignore[override]
201199 while True :
202200 try :
203201 # Poll for job execution status
204- response_from_hook = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
205- if response_from_hook == "success" :
202+ job_status = await hook .get_job_status (job_id = self .job_id , project_id = self .project_id )
203+ if job_status == "success" :
206204 query_results = await hook .get_job_output (job_id = self .job_id , project_id = self .project_id )
207205 records = hook .get_records (query_results = query_results , as_dict = self .as_dict )
208- self .log .debug ("Response from hook: %s" , response_from_hook )
206+ self .log .debug ("Response from hook: %s" , job_status )
209207 yield TriggerEvent (
210208 {
211209 "status" : "success" ,
212- "message" : response_from_hook ,
210+ "message" : job_status ,
213211 "records" : records ,
214212 }
215213 )
216214 return
217- elif response_from_hook == "pending" :
218- self .log .info ("Query is still running..." )
219- self .log .info ("Sleeping for %s seconds." , self .poll_interval )
220- await asyncio .sleep (self .poll_interval )
221- else :
222- yield TriggerEvent ({"status" : "error" , "message" : response_from_hook })
215+ elif job_status == "error" :
216+ yield TriggerEvent ({"status" : "error" })
223217 return
218+ else :
219+ self .log .info (
220+ "Bigquery job status is %s. Sleeping for %s seconds." , job_status , self .poll_interval
221+ )
222+ await asyncio .sleep (self .poll_interval )
224223 except Exception as e :
225224 self .log .exception ("Exception occurred while checking for query completion" )
226225 yield TriggerEvent ({"status" : "error" , "message" : str (e )})
0 commit comments