File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 44
55import datetime
66import logging
7+ import os
78import time
89import uuid
910from typing import TYPE_CHECKING , Literal , TypedDict , cast
1011
1112import eventer
13+ import httpx
1214import requests
1315import web
1416from simplejson .errors import JSONDecodeError
@@ -202,10 +204,22 @@ def get_groundtruth_availability(ocaid, s3_keys=None):
202204 including 1-hour borrows"""
203205 params = '?action=availability&identifier=' + ocaid
204206 url = S3_LOAN_URL % config_bookreader_host
207+ timeout = 2 if os .getenv ('LOCAL_DEV' ) else 5
205208 try :
206- response = requests .post (url + params , data = s3_keys )
209+ response = httpx .post (url + params , data = s3_keys , timeout = timeout )
207210 response .raise_for_status ()
208- except requests .HTTPError :
211+ except httpx .TimeoutException :
212+ if os .getenv ('LOCAL_DEV' ):
213+ logger .warning (
214+ "Availability request timed out in LOCAL_DEV environment. Returning empty dictionary."
215+ )
216+ return {}
217+ else :
218+ logger .error (
219+ "Availability request timed out in non-LOCAL_DEV environment. Re-raising the exception."
220+ )
221+ raise # Re-raise the timeout exception if not in LOCAL_DEV
222+ except httpx .HTTPError :
209223 pass # TODO: Handle unexpected responses from the availability server.
210224 try :
211225 data = response .json ().get ('lending_status' , {})
You can’t perform that action at this time.
0 commit comments