Skip to content

Commit 79cc8d8

Browse files
committed
add asyncio wait for to tackle task execution hanging
1 parent fe97729 commit 79cc8d8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

indexer_app/tasks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def indexer(from_block: int, to_block: int):
5252
# Log time before fetching a new block
5353
fetch_start_time = time.time()
5454
# streamer_message is the current block
55-
streamer_message = await streamer_messages_queue.get()
55+
streamer_message = await asyncio.wait_for(streamer_messages_queue.get(), 30)
5656
fetch_end_time = time.time()
5757
logger.info(
5858
f"Time to fetch new block: {fetch_end_time - fetch_start_time:.4f} seconds"
@@ -85,6 +85,11 @@ async def indexer(from_block: int, to_block: int):
8585
logger.info(
8686
f"Total time for one iteration: {iteration_end_time - fetch_start_time:.4f} seconds"
8787
)
88+
89+
90+
except asyncio.TimeoutError:
91+
logger.warning("Stream stalled: no new blocks within timeout, restarting...") # raise Exception so sytemd can restart the worker
92+
raise Exception("Stream stalled: restarting...")
8893

8994
except Exception as e:
9095
logger.error(f"Error in streamer_messages_queue: {e}")

0 commit comments

Comments
 (0)