diff --git a/backend/src/core/task_manager/task_logger.py b/backend/src/core/task_manager/task_logger.py index cb3c894a..4a77f051 100644 --- a/backend/src/core/task_manager/task_logger.py +++ b/backend/src/core/task_manager/task_logger.py @@ -4,6 +4,7 @@ # @RELATION DEPENDS_ON -> [TaskManager] # @RELATION DEPENDS_ON -> [EventBus] # @INVARIANT Each TaskLogger instance is bound to a specific task_id and default source. +import asyncio from collections.abc import Callable from typing import Any @@ -81,13 +82,21 @@ class TaskLogger: metadata: dict[str, Any] | None = None, ) -> None: """Internal logging method.""" - self._add_log( + coro = self._add_log( task_id=self._task_id, level=level, message=message, source=source or self._default_source, metadata=metadata, ) + # Fire-and-forget: schedule the async callback if a loop is running, + # otherwise drop gracefully (sync context, no event loop available). + try: + loop = asyncio.get_running_loop() + if loop.is_running(): + asyncio.ensure_future(coro) + except RuntimeError: + pass # #endregion _log # #region debug [TYPE Function] # @PURPOSE: Log a DEBUG level message. diff --git a/backend/src/plugins/debug.py b/backend/src/plugins/debug.py index 9e89a282..286425b3 100644 --- a/backend/src/plugins/debug.py +++ b/backend/src/plugins/debug.py @@ -167,8 +167,8 @@ class DebugPlugin(PluginBase): raise ValueError(f"Environment '{name}' not found.") client = SupersetClient(env_config) - client.authenticate() - count, dbs = client.get_databases() + await client.authenticate() + count, dbs = await client.get_databases() log.debug(f"Found {count} databases in {name}") results[name] = { "count": count, @@ -203,9 +203,9 @@ class DebugPlugin(PluginBase): raise ValueError(f"Environment '{env_name}' not found.") client = SupersetClient(env_config) - client.authenticate() + await client.authenticate() - dataset_response = client.get_dataset(dataset_id) + dataset_response = await client.get_dataset(dataset_id) log.debug(f"Retrieved dataset structure for {dataset_id}") return dataset_response.get('result') or {} # endregion _get_dataset_structure