@@ -108,7 +108,7 @@ async def _get_job_result():
108108 return res
109109 else :
110110 raise TypeError ("Task result must be a dict" )
111- except Exception as e :
111+ except Exception as e : # noqa: BLE001 - ARQ result failures are retried
112112 last_err = e
113113 await asyncio .sleep (0.05 )
114114 if last_err :
@@ -118,7 +118,7 @@ async def _get_job_result():
118118 if job_status == "complete" :
119119 response .result = await _get_job_result ()
120120 response .completed_at = (
121- metadata .get ("completed_at" ) or datetime .utcnow ( ).isoformat ()
121+ metadata .get ("completed_at" ) or datetime .now ( UTC ).isoformat ()
122122 )
123123 await websocket .send_json (response .dict ())
124124 await websocket .close (code = 1000 )
@@ -153,15 +153,15 @@ async def _get_job_result():
153153 if status_enum is None
154154 else _STATUS_MAP .get (status_enum , "unknown" )
155155 )
156- except Exception :
156+ except Exception : # noqa: BLE001 - status polling is best-effort
157157 current_status = last_sent_status
158158
159159 if current_status and current_status != last_sent_status :
160160 last_sent_status = current_status
161161
162162 if current_status == "complete" :
163163 result = await _get_job_result ()
164- completed_at = datetime .utcnow ( ).isoformat ()
164+ completed_at = datetime .now ( UTC ).isoformat ()
165165 metadata ["completed_at" ] = completed_at
166166 metadata ["status" ] = "complete"
167167 await redis .set (
@@ -228,7 +228,7 @@ async def _get_job_result():
228228
229229 result = await _get_job_result ()
230230
231- completed_at = datetime .utcnow ( ).isoformat ()
231+ completed_at = datetime .now ( UTC ).isoformat ()
232232 metadata ["completed_at" ] = completed_at
233233 metadata ["status" ] = "complete"
234234 await redis .set (
@@ -248,7 +248,7 @@ async def _get_job_result():
248248 )
249249 await websocket .close (code = 1000 )
250250 return
251- except Exception :
251+ except Exception : # noqa: BLE001 - close the WebSocket on an unexpected failure
252252 await websocket .close (code = 1011 )
253253 return
254254
@@ -311,7 +311,7 @@ async def submit_generate_task(
311311 metadata = {
312312 "user_id" : current_user .user_id ,
313313 "archive_ids" : request .archive_ids ,
314- "created_at" : datetime .utcnow ( ).isoformat (),
314+ "created_at" : datetime .now ( UTC ).isoformat (),
315315 "status" : "pending" ,
316316 }
317317 await redis .set (
@@ -328,7 +328,7 @@ async def submit_generate_task(
328328
329329 except HTTPException :
330330 raise
331- except Exception as e :
331+ except Exception as e : # noqa: BLE001 - translate unexpected backend failures
332332 raise HTTPException (
333333 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
334334 detail = f"Failed to submit task: { e !s} " ,
@@ -369,7 +369,7 @@ async def delete_task(
369369
370370 except HTTPException :
371371 raise
372- except Exception as e :
372+ except Exception as e : # noqa: BLE001 - translate unexpected backend failures
373373 raise HTTPException (
374374 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
375375 detail = f"Failed to delete task: { e !s} " ,
@@ -405,7 +405,7 @@ async def get_api_key_status(
405405 return ApiKeyResponse (has_api_key = has_api_key , api_key_masked = api_key_masked )
406406 except HTTPException :
407407 raise
408- except Exception as e :
408+ except Exception as e : # noqa: BLE001 - translate unexpected database failures
409409 raise HTTPException (
410410 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
411411 detail = f"Failed to get API key status: { e !s} " ,
@@ -452,7 +452,7 @@ async def update_api_key(
452452 return ApiKeyResponse (has_api_key = has_api_key , api_key_masked = api_key_masked )
453453 except HTTPException :
454454 raise
455- except Exception as e :
455+ except Exception as e : # noqa: BLE001 - translate validation and database failures
456456 # Check if it's an API key validation error
457457 if "API key" in str (e ) or "authentication" in str (e ).lower ():
458458 raise HTTPException (
0 commit comments