Add tear down
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user