diff --git a/src/schematic/event_buffer.py b/src/schematic/event_buffer.py index e5a4bfc..617bea5 100644 --- a/src/schematic/event_buffer.py +++ b/src/schematic/event_buffer.py @@ -114,6 +114,8 @@ def push(self, event: CreateEventRequestBody): def stop(self): try: self.stopped = True + # Do a final flush before shutting down to avoid losing buffered events + self._flush() self.shutdown.set() self.flush_thread.join(timeout=5) except Exception as e: @@ -222,6 +224,8 @@ async def push(self, event: CreateEventRequestBody): async def stop(self): try: self.stopped = True + # Do a final flush before shutting down to avoid losing buffered events + await self._flush() self.shutdown_event.set() await self.flush_task except Exception as e: