Skip to content

Commit

Permalink
add timeout to plannotate (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera authored Nov 26, 2024
1 parent f8e3c82 commit a57810c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dna_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ async def get_sequence_from_euroscarf_url(plasmid_id: str) -> Dseqrecord:


async def annotate_with_plannotate(
file_content: str, file_name: str, url: str
file_content: str, file_name: str, url: str, timeout: int = 20
) -> tuple[Dseqrecord, PlannotateAnnotationReport, str]:
async with httpx.AsyncClient() as client:
try:
response = await client.post(
url,
files={'file': (file_name, file_content, 'text/plain')},
timeout=20,
timeout=timeout,
)
if response.status_code != 200:
detail = response.json().get('detail', 'plannotate server error')
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
RECORD_STUBS = os.environ['RECORD_STUBS'] == '1' if 'RECORD_STUBS' in os.environ else False
SERVE_FRONTEND = os.environ['SERVE_FRONTEND'] == '1' if 'SERVE_FRONTEND' in os.environ else False
PLANNOTATE_URL = os.environ['PLANNOTATE_URL'] if 'PLANNOTATE_URL' in os.environ else None
PLANNOTATE_TIMEOUT = int(os.environ['PLANNOTATE_TIMEOUT']) if 'PLANNOTATE_TIMEOUT' in os.environ else 20

# Handle trailing slash:
if PLANNOTATE_URL is not None and not PLANNOTATE_URL.endswith('/'):
Expand Down Expand Up @@ -1360,7 +1361,7 @@ async def annotate_with_plannotate(
# Make a request submitting sequence as a file:
try:
seqr, annotations, version = await _annotate_with_plannotate(
sequence.file_content, f'{sequence.id}.gb', PLANNOTATE_URL + 'annotate'
sequence.file_content, f'{sequence.id}.gb', PLANNOTATE_URL + 'annotate', PLANNOTATE_TIMEOUT
)
except HTTPError as e:
raise HTTPException(e.code, e.msg) from e
Expand Down

0 comments on commit a57810c

Please sign in to comment.