From 3fe02e5f6e0e88d2dd5441f5a7f847d35f2d20f9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 23 Jan 2025 11:43:18 +0000 Subject: [PATCH] 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 --- src/buildservice/__init__.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) 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) -- 2.47.3