]> git.ipfire.org Git - pbs.git/commitdiff
backend: Run periodic tasks as a separate task
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Jan 2025 11:43:18 +0000 (11:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 23 Jan 2025 11:43:18 +0000 (11:43 +0000)
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>
src/buildservice/__init__.py

index 0c7797684fa734e2731ddcd78f82f08a8162cffe..4b7bfc3b9373497d425affdfbf135f526b1765ca 100644 (file)
@@ -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)