11import asyncio
22from asyncio import Queue , sleep
33from typing import Any , List
4- from .node import BaseNode
4+ from .node . BaseNode import BaseNode
55from aiohttp import ClientSession
6+ from logging import getLogger
67
8+ logger = getLogger (__name__ )
79
810class Runtime :
911
@@ -51,16 +53,20 @@ async def _enqueue_call(self):
5153 res = await response .json ()
5254
5355 if response .status != 200 :
54- raise Exception (f"Failed to enqueue states: { res } " )
56+ logger . error (f"Failed to enqueue states: { res } " )
5557
5658 return res
5759
5860 async def _enqueue (self ):
5961 while True :
60- if self ._state_queue .qsize () < self ._batch_size :
61- data = await self ._enqueue_call ()
62- for state in data ["states" ]:
63- await self ._state_queue .put (state )
62+ try :
63+ if self ._state_queue .qsize () < self ._batch_size :
64+ data = await self ._enqueue_call ()
65+ for state in data ["states" ]:
66+ await self ._state_queue .put (state )
67+ except Exception as e :
68+ logger .error (f"Error enqueuing states: { e } " )
69+
6470 await sleep (self ._poll_interval )
6571
6672 async def _notify_executed (self , state_id : str , outputs : dict [str , Any ]):
@@ -70,7 +76,10 @@ async def _notify_executed(self, state_id: str, outputs: dict[str, Any]):
7076 headers = {"x-api-key" : self ._key }
7177
7278 async with session .post (endpoint , json = body , headers = headers ) as response :
73- return await response .json ()
79+ res = await response .json ()
80+
81+ if response .status != 200 :
82+ logger .error (f"Failed to notify executed state { state_id } : { res } " )
7483
7584 async def _notify_errored (self , state_id : str , error : str ):
7685 async with ClientSession () as session :
@@ -79,7 +88,10 @@ async def _notify_errored(self, state_id: str, error: str):
7988 headers = {"x-api-key" : self ._key }
8089
8190 async with session .post (endpoint , json = body , headers = headers ) as response :
82- return await response .json ()
91+ res = await response .json ()
92+
93+ if response .status != 200 :
94+ logger .error (f"Failed to notify errored state { state_id } : { res } " )
8395
8496 def _validate_nodes (self , nodes : List [BaseNode ]):
8597 invalid_nodes = []
0 commit comments