def run_task(self) -> None:
'''Execute the task inside the asyncio event loop. Track the time it
takes to run, and log when it starts/stops. After `INTERVAL` seconds,
if/once the task has finished running, run it again until `stop()`
is called.'''
while self.running:
try:
Log.debug('executing periodic task %s', self.name)
before = self.time()
await self.run()
total = self.time() - before
Log.debug('finished periodic task %s in %.1f seconds',
self.name, total)
sleep = self.INTERVAL - total
if sleep > 0:
await self.sleep(sleep)
except CancelledError:
Log.debug('cancelled periodic task %s', self.name)
raise
except Exception:
Log.exception('exception in periodic task %s', self.name)
评论列表
文章目录