Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the startup event of the power board. #1209

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/panoptes/pocs/utils/service/power.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from enum import auto
from typing import Union

Expand All @@ -20,18 +21,19 @@ class RelayCommand(BaseModel):
command: RelayAction


app = FastAPI()
power_board: PowerBoard
read_interval = get_config('environment.power.read_interval', default=60)


@app.on_event('startup')
async def startup():
@asynccontextmanager
async def startup(app: FastAPI):
global power_board
power_board = PowerBoard(**get_config('environment.power', {}))
yield


app = FastAPI(lifespan=startup)


@app.on_event('startup')
@repeat_every(seconds=60, wait_first=True)
def record_readings():
"""Record the current readings in the db."""
Expand Down