@@ -166,7 +166,7 @@ async def upload_data(
166166 http ._redirected_url_due_to_tsload_load_balancer = httpx .URL (host = redirect ["host" ], port = redirect ["port" ]) # type: ignore[attr-defined]
167167 # DEV NOTE: @boonhapus, 2025/01/28
168168 # Technically speaking, this endpoint just delegates to the AUTH SERVICE on each node, so any persistent login
169- # API method would work here, it just needs to point at the redirected node. CS Tools offers multiple login
169+ # API method should work here, it just needs to point at the redirected node. CS Tools offers multiple login
170170 # methods, but it's a pretty safe bet that the customer on Falcon will have a BASIC auth context.
171171 r = await http .v1_dataservice_dataload_session (** auth_info )
172172 r .raise_for_status ()
@@ -182,19 +182,30 @@ async def upload_data(
182182 return data ["cycle_id" ]
183183
184184
185- async def wait_for_dataload_completion (cycle_id : _types .GUID , * , http : RESTAPIClient ) -> _types .APIResult :
185+ async def wait_for_dataload_completion (
186+ cycle_id : _types .GUID ,
187+ * ,
188+ timeout : int = 300 ,
189+ http : RESTAPIClient ,
190+ ) -> _types .APIResult :
186191 """Wait for dataload to complete."""
192+ start = dt .datetime .now (tz = dt .timezone .utc )
193+
187194 while True :
188195 _LOG .info (f"Checking status of dataload { cycle_id } ..." )
189196 r = await http .v1_dataservice_dataload_status (cycle_id = cycle_id )
190197
191198 status_data = r .json ()
192199
193- if "code" in status_data ["status" ]:
200+ if "code" in status_data .get ("status" , {}):
201+ break
202+
203+ if (dt .datetime .now (tz = dt .timezone .utc ) - start ).seconds >= timeout :
204+ _LOG .warning (f"Reached the { timeout / 60 :.1f} minute CS Tools timeout, giving up on cycle_id { cycle_id } " )
194205 break
195206
196207 _LOG .debug (status_data )
197- await asyncio .sleep (1 )
208+ await asyncio .sleep (5 )
198209
199210 _LOG .info (
200211 f"Cycle ID: { status_data ['cycle_id' ]} ({ status_data ['status' ]['code' ]} )"
0 commit comments