Skip to content

Commit

Permalink
Run first extraction before starting webserver
Browse files Browse the repository at this point in the history
It leaves less time for client to hit 503 error on startup, but more importantly, it deals with race condition in startup sequence: if extractor_task gets interrupted after webserver startup was initiated but before make_server() returned, then potoken_server.stop() becomes a no-op, leaving background task with webserver to run indefinitely.
  • Loading branch information
15532th authored and unixfox committed Nov 17, 2024
1 parent 722fd47 commit 3b3a5c4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion potoken_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def print_token_and_exit(token_info: Optional[TokenInfo]):
async def run(loop: asyncio.AbstractEventLoop, oneshot: bool,
update_interval: int, bind_address: str, port: int) -> None:
potoken_extractor = PotokenExtractor(loop, update_interval=update_interval)
token = await potoken_extractor.run_once()
if oneshot:
token = await potoken_extractor.run_once()
print_token_and_exit(token)

extractor_task = loop.create_task(potoken_extractor.run())
Expand Down

0 comments on commit 3b3a5c4

Please sign in to comment.