Skip to content

Commit 6eaa3c5

Browse files
committed
add: add retry for all API usage in RNA search
1 parent 5256670 commit 6eaa3c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

graphgen/models/searcher/db/rnacentral_searcher.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ def _calculate_md5(sequence: str) -> str:
151151

152152
return hashlib.md5(normalized_seq.encode("ascii")).hexdigest()
153153

154+
@retry(
155+
stop=stop_after_attempt(3),
156+
wait=wait_exponential(multiplier=1, min=2, max=10),
157+
retry=retry_if_exception_type((requests.Timeout, requests.RequestException)),
158+
reraise=False,
159+
)
154160
def get_by_rna_id(self, rna_id: str) -> Optional[dict]:
155161
"""
156162
Get RNA information by RNAcentral ID.
@@ -178,6 +184,12 @@ def get_by_rna_id(self, rna_id: str) -> Optional[dict]:
178184
logger.error("Unexpected error getting RNA ID %s: %s", rna_id, e)
179185
return None
180186

187+
@retry(
188+
stop=stop_after_attempt(3),
189+
wait=wait_exponential(multiplier=1, min=2, max=10),
190+
retry=retry_if_exception_type((requests.Timeout, requests.RequestException)),
191+
reraise=False,
192+
)
181193
def get_best_hit(self, keyword: str) -> Optional[dict]:
182194
"""
183195
Search RNAcentral with a keyword and return the best hit.

0 commit comments

Comments
 (0)