Files
semantic-kernel/python/semantic_kernel/reliability/pass_through_without_retry.py
T
Julio Carlos MenendezandEvan Mattson d97f9536c4 Python: Removes the _async suffix where is not needed (#4735)
### Motivation and Context
Delete all *_async where *_sync doesn't exist to make the library more
Pythonic.

Fixes #4629 

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <[email protected]>
2024-01-26 17:15:35 +00:00

33 lines
1.1 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
import logging
from typing import Any, Awaitable, Callable, Optional, TypeVar
from semantic_kernel.kernel_pydantic import KernelBaseModel
from semantic_kernel.reliability.retry_mechanism_base import RetryMechanismBase
T = TypeVar("T")
logger: logging.Logger = logging.getLogger(__name__)
class PassThroughWithoutRetry(RetryMechanismBase, KernelBaseModel):
"""A retry mechanism that does not retry."""
async def execute_with_retry(self, action: Callable[[], Awaitable[T]], log: Optional[Any] = None) -> Awaitable[T]:
"""Executes the given action with retry logic.
Arguments:
action {Callable[[], Awaitable[T]]} -- The action to retry on exception.
Returns:
Awaitable[T] -- An awaitable that will return the result of the action.
"""
if log:
logger.warning("The `log` parameter is deprecated. Please use the `logging` module instead.")
try:
await action()
except Exception as e:
logger.warning(e, "Error executing action, not retrying")
raise