Skip to content

Commit

Permalink
Add delay and retry on gene API fetch failure
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Oct 23, 2024
1 parent 783b74f commit e6bece4
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

import pandas as pd
import requests
from loguru import logger

from brainrender import base_dir
Expand Down Expand Up @@ -86,7 +87,16 @@ def get_gene_experiments(self, gene):
:param gene_symbol: str
"""
url = self.gene_experiments_url.replace("-GENE_SYMBOL-", gene)
data = request(url).json()["msg"]
max_retries = 5
delay = 4

for i in range(max_retries):
try:
data = request(url).json()["msg"]
break
except requests.exceptions.JSONDecodeError:
print(f"Unable to connect to Allen API, retrying in {delay}")
delay *= 2

if not len(data):
print(f"No experiment found for gene {gene}")
Expand Down

0 comments on commit e6bece4

Please sign in to comment.