From: Michael Tremer Date: Thu, 23 Jan 2025 11:43:18 +0000 (+0000) Subject: backend: Run periodic tasks as a separate task X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fe02e5f6e0e88d2dd5441f5a7f847d35f2d20f9;p=pbs.git backend: Run periodic tasks as a separate task 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 --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index 0c779768..4b7bfc3b 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -216,15 +216,8 @@ class Backend(object): 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)