Skip to content

Commit

Permalink
Update metrics tracker decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shirokov committed Jun 25, 2024
1 parent 5c12b59 commit 84c4c94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions sns_sqs_communicator/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sns_sqs_communicator/sqs_poll_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 84c4c94

Please sign in to comment.