Update settings

This commit is contained in:
Kai Vogelgesang 2022-10-28 16:57:49 +02:00
parent 12a3eb2045
commit 09bc5a0f59
3 changed files with 12 additions and 9 deletions

View File

@ -5,9 +5,10 @@ from hypercorn.asyncio import serve
from .web import app from .web import app
from .pag import Runner from .pag import Runner
from .settings import settings
config = Config() config = Config()
config.bind = ["0.0.0.0:8000"] config.bind = [settings.bind]
pag_runner = Runner() pag_runner = Runner()
pag_runner.start() pag_runner.start()

View File

@ -49,7 +49,7 @@ class ClientState:
self.inactivity_task = asyncio.create_task(self.deactivator()) self.inactivity_task = asyncio.create_task(self.deactivator())
async def deactivator(self): async def deactivator(self):
await asyncio.sleep(settings.CLIENT_IDLE_TIMEOUT) await asyncio.sleep(settings.client_idle_timeout)
self.is_active = False self.is_active = False
self.inactivity_task = None self.inactivity_task = None
@ -119,7 +119,7 @@ class Arbiter:
self.state.mode = self.current_mode.name self.state.mode = self.current_mode.name
self.update_next_mode() self.update_next_mode()
self.modeswitch_time = datetime.now() + timedelta( self.modeswitch_time = datetime.now() + timedelta(
seconds=settings.ARBITER_MODE_SWITCH_CYCLE seconds=settings.arbiter_mode_switch_cycle
) )
if self.current_mode_task: if self.current_mode_task:
@ -135,7 +135,7 @@ class Arbiter:
).total_seconds() ).total_seconds()
await asyncio.gather( await asyncio.gather(
asyncio.sleep(settings.ARBITER_TICK_CYCLE), asyncio.sleep(settings.arbiter_tick_cycle),
*[ *[
socket.send_json( socket.send_json(
{ {
@ -155,7 +155,7 @@ arbiter = Arbiter()
@arbiter.mode("democracy", allow_multitouch=False) @arbiter.mode("democracy", allow_multitouch=False)
async def _(get_input: InputGetter, set_output: OutputSetter): async def _(get_input: InputGetter, set_output: OutputSetter):
while True: while True:
await asyncio.sleep(settings.DEMOCRACY_VOTE_CYCLE) await asyncio.sleep(settings.democracy_vote_cycle)
vote = {button: 0 for button in Button} vote = {button: 0 for button in Button}
vote["none"] = 0 vote["none"] = 0

View File

@ -2,12 +2,14 @@ from pydantic import BaseSettings
class Settings(BaseSettings): class Settings(BaseSettings):
CLIENT_IDLE_TIMEOUT: float = 10 bind: str = "0.0.0.0:8000"
ARBITER_TICK_CYCLE: float = 0.1 client_idle_timeout: float = 10
ARBITER_MODE_SWITCH_CYCLE: float = 10
DEMOCRACY_VOTE_CYCLE: float = 0.25 arbiter_tick_cycle: float = 0.1
arbiter_mode_switch_cycle: float = 10
democracy_vote_cycle: float = 0.25
settings = Settings() settings = Settings()