Skip to content

Commit

Permalink
Fixes customized CMR_TIMEOUT, sets timeout to 60 on intersection test
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Aug 2, 2024
1 parent 58390d7 commit abcbc0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions asf_search/search/search_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def process_page(items: List[ASFProduct], max_results: int, subquery_max_results
stop=stop_after_attempt(3),
)
def get_page(session: ASFSession, url: str, translated_opts: List) -> Response:

from asf_search.constants.INTERNAL import CMR_TIMEOUT
perf = time.time()
try:
response = session.post(url=url, data=translated_opts, timeout=INTERNAL.CMR_TIMEOUT)
response = session.post(url=url, data=translated_opts, timeout=CMR_TIMEOUT)
response.raise_for_status()
except HTTPError as exc:
error_message = f'HTTP {response.status_code}: {response.json()["errors"]}'
Expand All @@ -197,7 +197,7 @@ def get_page(session: ASFSession, url: str, translated_opts: List) -> Response:
if 500 <= response.status_code <= 599:
raise ASFSearch5xxError(error_message) from exc
except ReadTimeout as exc:
raise ASFSearchError(f'Connection Error (Timeout): CMR took too long to respond. Set asf constant "CMR_TIMEOUT" to increase. ({url=}, timeout={INTERNAL.CMR_TIMEOUT})') from exc
raise ASFSearchError(f'Connection Error (Timeout): CMR took too long to respond. Set asf constant "asf_search.constants.INTERNAL.CMR_TIMEOUT" to increase. ({url=}, timeout={CMR_TIMEOUT})') from exc

ASF_LOGGER.warning(f"Query Time Elapsed {time.time() - perf}")
return response
Expand Down
15 changes: 10 additions & 5 deletions tests/ASFSearchResults/test_ASFSearchResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from asf_search.constants import PLATFORM
import re

from asf_search.exceptions import ASFSearchError

# when this replaces SearchAPI change values to cached
API_URL = 'https://api.daac.asf.alaska.edu/services/search/param?'

Expand Down Expand Up @@ -198,18 +200,21 @@ def run_test_ASFSearchResults_intersection(wkt: str):

# exclude SMAP products
platforms = [
PLATFORM.ALOS,
PLATFORM.SENTINEL1,
PLATFORM.SIRC,
PLATFORM.UAVSAR
]

def overlap_check(s1: BaseGeometry, s2: BaseGeometry):
return s1.overlaps(s2) or s1.touches(s2) or s2.distance(s1) <= 0.005

asf.constants.INTERNAL.CMR_TIMEOUT = 60
for platform in platforms:
results = asf.geo_search(intersectsWith=wkt, platform=platform, maxResults=250)

try:
results = asf.geo_search(intersectsWith=wkt, platform=platform, maxResults=250)
except ASFSearchError as exc:
asf.constants.INTERNAL.CMR_TIMEOUT = 30
raise BaseException(f'Failed to perform intersection test with wkt: {wkt}\nplatform: {platform}.\nOriginal exception: {exc}')

asf.constants.INTERNAL.CMR_TIMEOUT = 30
for product in results:
if shape(product.geometry).is_valid:
product_geom_wrapped, product_geom_unwrapped, _ = asf.validate_wkt(shape(product.geometry))
Expand Down

0 comments on commit abcbc0d

Please sign in to comment.