From 9ac6bf779fc2d0ff5e2f63dcd23271669dfd844f Mon Sep 17 00:00:00 2001 From: Igor Gorohovsky Date: Fri, 21 Mar 2025 22:32:07 +0200 Subject: [PATCH 1/3] warn on .wait_result call if there is no result backend --- taskiq/task.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/taskiq/task.py b/taskiq/task.py index c54e9d46..c2481a60 100644 --- a/taskiq/task.py +++ b/taskiq/task.py @@ -1,4 +1,5 @@ import asyncio +from logging import getLogger from time import time from typing import TYPE_CHECKING, Any, Generic, Optional @@ -9,6 +10,7 @@ ResultIsReadyError, TaskiqResultTimeoutError, ) +from taskiq.result_backends.dummy import DummyResultBackend if TYPE_CHECKING: # pragma: no cover from taskiq.abc.result_backend import AsyncResultBackend @@ -18,6 +20,9 @@ _ReturnType = TypeVar("_ReturnType") +logger = getLogger("taskiq") + + class AsyncTaskiqTask(Generic[_ReturnType]): """AsyncTask for AsyncResultBackend.""" @@ -83,6 +88,9 @@ async def wait_result( become ready in provided period of time. :return: task's return value. """ + if isinstance(self.result_backend, DummyResultBackend): + logger.warning("No result backend configured. Returning dummy result...") + start_time = time() while not await self.is_ready(): await asyncio.sleep(check_interval) From 7bc85e374f89fdd4bd373c7757c74b55c66e17e1 Mon Sep 17 00:00:00 2001 From: Igor Gorohovsky Date: Sun, 23 Mar 2025 15:41:10 +0200 Subject: [PATCH 2/3] warn user on dummy result backend level --- taskiq/result_backends/dummy.py | 6 ++++++ taskiq/task.py | 8 -------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/taskiq/result_backends/dummy.py b/taskiq/result_backends/dummy.py index 50550f80..4f98a637 100644 --- a/taskiq/result_backends/dummy.py +++ b/taskiq/result_backends/dummy.py @@ -1,3 +1,4 @@ +from logging import getLogger from typing import Any, TypeVar from taskiq.abc.result_backend import AsyncResultBackend @@ -6,6 +7,9 @@ _ReturnType = TypeVar("_ReturnType") +logger = getLogger("taskiq") + + class DummyResultBackend(AsyncResultBackend[_ReturnType]): # pragma: no cover """Default result backend, that does nothing.""" @@ -41,6 +45,8 @@ async def get_result(self, task_id: str, with_logs: bool = False) -> Any: :param with_logs: wether to fetch logs. :returns: TaskiqResult. """ + logger.warning("No result backend configured. Returning dummy result...") + return TaskiqResult( is_err=False, log=None, diff --git a/taskiq/task.py b/taskiq/task.py index c2481a60..c54e9d46 100644 --- a/taskiq/task.py +++ b/taskiq/task.py @@ -1,5 +1,4 @@ import asyncio -from logging import getLogger from time import time from typing import TYPE_CHECKING, Any, Generic, Optional @@ -10,7 +9,6 @@ ResultIsReadyError, TaskiqResultTimeoutError, ) -from taskiq.result_backends.dummy import DummyResultBackend if TYPE_CHECKING: # pragma: no cover from taskiq.abc.result_backend import AsyncResultBackend @@ -20,9 +18,6 @@ _ReturnType = TypeVar("_ReturnType") -logger = getLogger("taskiq") - - class AsyncTaskiqTask(Generic[_ReturnType]): """AsyncTask for AsyncResultBackend.""" @@ -88,9 +83,6 @@ async def wait_result( become ready in provided period of time. :return: task's return value. """ - if isinstance(self.result_backend, DummyResultBackend): - logger.warning("No result backend configured. Returning dummy result...") - start_time = time() while not await self.is_ready(): await asyncio.sleep(check_interval) From 1a55273707d6322764261d0770987f1a4d9406c5 Mon Sep 17 00:00:00 2001 From: Igor Gorohovsky Date: Mon, 24 Mar 2025 10:18:52 +0200 Subject: [PATCH 3/3] use warn from warnings module --- taskiq/result_backends/dummy.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/taskiq/result_backends/dummy.py b/taskiq/result_backends/dummy.py index 4f98a637..e9d427b5 100644 --- a/taskiq/result_backends/dummy.py +++ b/taskiq/result_backends/dummy.py @@ -1,4 +1,4 @@ -from logging import getLogger +import warnings from typing import Any, TypeVar from taskiq.abc.result_backend import AsyncResultBackend @@ -7,9 +7,6 @@ _ReturnType = TypeVar("_ReturnType") -logger = getLogger("taskiq") - - class DummyResultBackend(AsyncResultBackend[_ReturnType]): # pragma: no cover """Default result backend, that does nothing.""" @@ -45,7 +42,10 @@ async def get_result(self, task_id: str, with_logs: bool = False) -> Any: :param with_logs: wether to fetch logs. :returns: TaskiqResult. """ - logger.warning("No result backend configured. Returning dummy result...") + warnings.warn( + "No result backend configured. Returning dummy result...", + stacklevel=2, + ) return TaskiqResult( is_err=False,