From 84c4c94a9ca19cc02bb14d6d9ba5df89caab6138 Mon Sep 17 00:00:00 2001 From: Sergey Shirokov Date: Tue, 25 Jun 2024 11:19:03 +0500 Subject: [PATCH] Update metrics tracker decorator --- sns_sqs_communicator/metrics.py | 15 +++++++++------ sns_sqs_communicator/sqs_poll_worker.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sns_sqs_communicator/metrics.py b/sns_sqs_communicator/metrics.py index 5a37bda..a292eeb 100644 --- a/sns_sqs_communicator/metrics.py +++ b/sns_sqs_communicator/metrics.py @@ -5,24 +5,27 @@ import os import typing +FP = typing.ParamSpec("FP") # Function Parameters +RV = typing.TypeVar("RV") # Returned Value + def tracker( - func: collections.abc.Callable[..., typing.Any], -) -> typing.Any: + func: collections.abc.Callable[FP, RV], +) -> collections.abc.Callable[FP, RV]: """Create a placeholder for performance tracker.""" @functools.wraps(func) def wrapper_tracker( - *args: typing.Any, - **kwargs: typing.Any, - ) -> typing.Any: + *args: FP.args, + **kwargs: FP.kwargs, + ) -> RV: return func(*args, **kwargs) return wrapper_tracker with contextlib.suppress(KeyError): # pragma: no cover - metric_tracker_path = os.environ["SNS_SQS_COMMUNICATOR_METRIC_TRACKER"] + metric_tracker_path = os.environ["FASTAPI_REST_FRAMEWORK_METRIC_TRACKER"] *module, tracker_name = metric_tracker_path.split(".") tracker = getattr(importlib.import_module(".".join(module)), tracker_name) # noqa: F811 diff --git a/sns_sqs_communicator/sqs_poll_worker.py b/sns_sqs_communicator/sqs_poll_worker.py index 873aad7..1d1a390 100644 --- a/sns_sqs_communicator/sqs_poll_worker.py +++ b/sns_sqs_communicator/sqs_poll_worker.py @@ -225,7 +225,7 @@ async def handle_processing_error( cls, raw_message: mypy_boto3_sqs.type_defs.MessageTypeDef, error: Exception, - parser: parsers.ParserProtocol[messages.MessageActionT], + parser: type[parsers.ParserProtocol[messages.MessageActionT]], dead_letter_queue: queue.SQSQueue, logger: logging.Logger, ) -> None: