Add tear down

This commit is contained in:
2024-08-27 16:42:08 +02:00
parent 6d12f2850d
commit 28908255e7
3 changed files with 6 additions and 1 deletions

View File

@@ -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."
}

View File

@@ -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)

View File

@@ -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)