Kumi
e82ccb2701
- Extended copyright to reflect the current year. - Incremented project version to indicate new features and fixes. - Added a new script entry for easier execution, increasing utility and accessibility. - Updated project URLs for better alignment with current infrastructure. - Refactored settings path for simplicity and consistency across deployments. - Improved code readability and maintenance across several modules by cleaning up redundant code, adding missing type annotations, and ensuring consistent code formatting. - Enhanced logging capabilities and error handling to improve diagnostics and troubleshooting, supporting more robust error recovery mechanisms. - Implemented more graceful handling of termination signals to ensure clean shutdown and resource cleanup, enhancing the robustness of the application in production environments. - Introduced command-line argument parsing for configuration file path customization, improving flexibility in different runtime environments. These changes collectively improve the project's maintainability, reliability, and user experience, laying a stronger foundation for future development.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from paramiko.ssh_exception import SSHException, NoValidConnectionsError
|
|
from socket import timeout
|
|
|
|
from .logger import Logger
|
|
|
|
|
|
class retry:
|
|
"""Decorator used to automatically retry operations throwing exceptions"""
|
|
|
|
def __init__(self, exceptions: tuple[BaseException] = None):
|
|
"""Initializing the retry decorator
|
|
|
|
Args:
|
|
exceptions (tuple, optional): A tuple containing exception classes
|
|
that should be handled by the decorator. If none, handle only
|
|
paramiko.ssh_exception.SSHException/NoValidConnectionsError and
|
|
socket.timeout/TimeoutError. Defaults to None.
|
|
"""
|
|
self.exceptions = exceptions or (
|
|
SSHException,
|
|
NoValidConnectionsError,
|
|
timeout,
|
|
TimeoutError,
|
|
)
|
|
self._logger = Logger()
|
|
|
|
def __call__(self, f):
|
|
"""Return a function through the retry decorator
|
|
|
|
Args:
|
|
f (function): Function to wrap in the decorator
|
|
|
|
Returns:
|
|
function: Function wrapping the passed function
|
|
"""
|
|
|
|
def wrapped_f(*args, **kwargs):
|
|
while True:
|
|
try:
|
|
return f(*args, **kwargs)
|
|
except self.exceptions as e:
|
|
self._logger.info("Caught expected exception: " + repr(e))
|
|
|
|
return wrapped_f
|