This is the easiest option to ensure that any changes will be committed
to the database in the end. When we run the callback in the same task,
we will never release the database session and therfore have no
automatic commit.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
log.debug("Periodic callback %r started" % callback)
while True:
- try:
- ret = callback(*args)
-
- # Await ret if callback is a coroutine
- if inspect.isawaitable(ret):
- await ret
-
- except Exception as e:
- log.error("Exception in periodic callback %r" % callback, exc_info=True)
+ # Run the callback in a separate task
+ self.run_task(callback, *args)
# Wait a little moment
await asyncio.sleep(delay)