diff --git a/helper/install.sh b/helper/install.sh index f608f3b..a0595db 100755 --- a/helper/install.sh +++ b/helper/install.sh @@ -83,7 +83,7 @@ uninstall_backend() { sudo rm /etc/supervisor/conf.d/$SUPERVISOR_CFG - rm -rf $TARGET_DIR + rm -rf $TARGET_DIR/src $TARGET_DIR/requirements.txt $TARGET_DIR/venv echo "Uninstallation complete." } diff --git a/src/main.py b/src/main.py index f4d3ce5..9eadbc8 100644 --- a/src/main.py +++ b/src/main.py @@ -29,6 +29,7 @@ async def _lifespan(_app: FastAPI): # noqa: ANN202 await location_recorder.create_db_engine() yield await mqtt.stop() + await location_recorder.dispose_db_engine() app = FastAPI(lifespan=_lifespan) diff --git a/src/util/location_recorder.py b/src/util/location_recorder.py index a1591d1..f6158a8 100644 --- a/src/util/location_recorder.py +++ b/src/util/location_recorder.py @@ -41,6 +41,9 @@ class LocationRecorder: async with self._engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) + async def dispose_db_engine(self) -> None: + await self._engine.dispose() + async def insert_location(self, people: str, datetime: str, location: LocationData) -> None: async with self._engine.connect() as conn: await conn.execute( @@ -53,6 +56,7 @@ class LocationRecorder: ), ) await conn.commit() + await conn.aclose() async def insert_location_now(self, people: str, location: LocationData) -> None: now = datetime.datetime.now(tz=datetime.UTC)