Commit 4038e805 authored by fred's avatar fred

stamina: realign interrupt clock every ten cycles

parent 1f06b2d6
...@@ -525,6 +525,7 @@ class Command(BaseCommand): ...@@ -525,6 +525,7 @@ class Command(BaseCommand):
async def recompute_slots_loop(self): async def recompute_slots_loop(self):
now = datetime.datetime.now() now = datetime.datetime.now()
sleep = (60 - now.second) % 10 # adjust to awake at :00 sleep = (60 - now.second) % 10 # adjust to awake at :00
i = 0
while not self.quit: while not self.quit:
await asyncio.sleep(sleep) await asyncio.sleep(sleep)
sleep = 10 # next cycles every 10 seconds sleep = 10 # next cycles every 10 seconds
...@@ -558,6 +559,14 @@ class Command(BaseCommand): ...@@ -558,6 +559,14 @@ class Command(BaseCommand):
# more than 5 minutes left, recompute playlist # more than 5 minutes left, recompute playlist
self.recompute_playlist() self.recompute_playlist()
i += 1
if i == 10:
# realign clock every ten cycles
now = datetime.datetime.now()
# adjust to awake at :00
sleep = ((60 - now.second) % 10) or 10
i = 0
async def handle_connection(self, reader, writer): async def handle_connection(self, reader, writer):
writer.write(b'Watusi!\n') writer.write(b'Watusi!\n')
writer.write(b'Known commands: status, softquit, hardquit\n') writer.write(b'Known commands: status, softquit, hardquit\n')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment