From 73df559c3e9e8400c499f070ff5af64de20e8b3d Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 14 Dec 2023 03:17:50 +0200 Subject: [PATCH 1/2] Add internal timeout. --- moonstreamapi/moonstreamapi/routes/queries.py | 3 ++- moonstreamapi/moonstreamapi/settings.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/moonstreamapi/moonstreamapi/routes/queries.py b/moonstreamapi/moonstreamapi/routes/queries.py index 5a1a0189..26e8b123 100644 --- a/moonstreamapi/moonstreamapi/routes/queries.py +++ b/moonstreamapi/moonstreamapi/routes/queries.py @@ -32,6 +32,7 @@ from ..settings import ( MOONSTREAM_APPLICATION_ID, MOONSTREAM_CRAWLERS_SERVER_PORT, MOONSTREAM_CRAWLERS_SERVER_URL, + MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS, MOONSTREAM_QUERIES_JOURNAL_ID, MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE, MOONSTREAM_S3_QUERIES_BUCKET, @@ -473,7 +474,7 @@ async def update_query_data_handler( if request_update.blockchain else None, }, - timeout=5, + timeout=MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS, ) except Exception as e: logger.error(f"Error interaction with crawlers: {str(e)}") diff --git a/moonstreamapi/moonstreamapi/settings.py b/moonstreamapi/moonstreamapi/settings.py index 95f7491a..1ae46003 100644 --- a/moonstreamapi/moonstreamapi/settings.py +++ b/moonstreamapi/moonstreamapi/settings.py @@ -259,3 +259,11 @@ supportsInterface_abi = [ "type": "function", } ] + +MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = os.environ.get( + "MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS", "10" +) + +MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = int( + MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS +) From 8bf0e723f0a14e2a927d4591f86c9899943ebd69 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 14 Dec 2023 03:35:55 +0200 Subject: [PATCH 2/2] Add suggested changes. --- moonstreamapi/moonstreamapi/settings.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/moonstreamapi/moonstreamapi/settings.py b/moonstreamapi/moonstreamapi/settings.py index 1ae46003..cf1db9a0 100644 --- a/moonstreamapi/moonstreamapi/settings.py +++ b/moonstreamapi/moonstreamapi/settings.py @@ -260,10 +260,16 @@ supportsInterface_abi = [ } ] -MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = os.environ.get( - "MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS", "10" -) - -MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = int( - MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS +MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS_RAW = os.environ.get( + "MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS" ) +MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = 10 +try: + if MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS_RAW is not None: + MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS = int( + MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS_RAW + ) +except: + raise Exception( + f"Could not parse MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS as int: {MOONSTREAM_INTERNAL_REQUEST_TIMEOUT_SECONDS_RAW}" + )