replace case statements with if/else to support python 3.9

This commit is contained in:
Lincoln Stein 2023-09-24 22:51:24 -04:00 committed by psychedelicious
parent 5a9777d443
commit f37ffda966
2 changed files with 29 additions and 21 deletions

View File

@ -47,20 +47,27 @@ class DefaultSessionProcessor(SessionProcessorBase):
async def _on_queue_event(self, event: FastAPIEvent) -> None: async def _on_queue_event(self, event: FastAPIEvent) -> None:
event_name = event[1]["event"] event_name = event[1]["event"]
match event_name: # This was a match statement, but match is not supported on python 3.9
case "graph_execution_state_complete" | "invocation_error" | "session_retrieval_error" | "invocation_retrieval_error": if event_name in [
self.__queue_item = None "graph_execution_state_complete",
self._poll_now() "invocation_error",
case "session_canceled" if self.__queue_item is not None and self.__queue_item.session_id == event[1][ "session_retrieval_error",
"data" "invocation_retrieval_error",
]["graph_execution_state_id"]: ]:
self.__queue_item = None self.__queue_item = None
self._poll_now() self._poll_now()
case "batch_enqueued": elif (
self._poll_now() event_name == "session_canceled"
case "queue_cleared": and self.__queue_item is not None
self.__queue_item = None and self.__queue_item.session_id == event[1]["data"]["graph_execution_state_id"]
self._poll_now() ):
self.__queue_item = None
self._poll_now()
elif event_name == "batch_enqueued":
self._poll_now()
elif event_name == "queue_cleared":
self.__queue_item = None
self._poll_now()
def resume(self) -> SessionProcessorStatus: def resume(self) -> SessionProcessorStatus:
if not self.__resume_event.is_set(): if not self.__resume_event.is_set():

View File

@ -59,13 +59,14 @@ class SqliteSessionQueue(SessionQueueBase):
async def _on_session_event(self, event: FastAPIEvent) -> FastAPIEvent: async def _on_session_event(self, event: FastAPIEvent) -> FastAPIEvent:
event_name = event[1]["event"] event_name = event[1]["event"]
match event_name:
case "graph_execution_state_complete": # This was a match statement, but match is not supported on python 3.9
await self._handle_complete_event(event) if event_name == "graph_execution_state_complete":
case "invocation_error" | "session_retrieval_error" | "invocation_retrieval_error": await self._handle_complete_event(event)
await self._handle_error_event(event) elif event_name in ["invocation_error", "session_retrieval_error", "invocation_retrieval_error"]:
case "session_canceled": await self._handle_error_event(event)
await self._handle_cancel_event(event) elif event_name == "session_canceled":
await self._handle_cancel_event(event)
return event return event
async def _handle_complete_event(self, event: FastAPIEvent) -> None: async def _handle_complete_event(self, event: FastAPIEvent) -> None: