Title: Implement minimal core framework with PL injection and update build config
Key features implemented: - Updated package metadata and dependencies in PKG-INFO, setup files - Added main.py entry point for backward compatibility with README launch method - Enhanced CLI with config options, system info command, and proper signal handling - Implemented minimal PluginManager loading only plugin-loader core plugin - Refactored PluginLoader to follow minimal core design, removed sandbox/isolation complexity - Updated auto-dependency plugin with safer PL injection mechanism and disabled pl_injection - Removed legacy plugin files (firewall, frp_proxy, ftp_server, multi_lang_deploy, ops_toolbox, security_gateway) as functionality moved to core plugin system - Improved gitignore with comprehensive ignore patterns The changes implement a minimal core framework design where only the plugin-loader is directly loaded by the core, with all other plugins managed through the PL injection mechanism, significantly simplifying the architecture.
This commit is contained in:
39
store/@{FutureOSS}/plugin-loader-pro/retry/handler.py
Normal file
39
store/@{FutureOSS}/plugin-loader-pro/retry/handler.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""重试处理器"""
|
||||
import time
|
||||
import random
|
||||
from typing import Callable, Any
|
||||
from ..core.config import RetryConfig
|
||||
from ..utils.logger import ProLogger
|
||||
|
||||
|
||||
class RetryHandler:
|
||||
"""重试处理器"""
|
||||
|
||||
def __init__(self, config: RetryConfig = None):
|
||||
config = config or RetryConfig()
|
||||
self.max_retries = config.max_retries
|
||||
self.backoff_factor = config.backoff_factor
|
||||
self.initial_delay = config.initial_delay
|
||||
|
||||
def execute(self, func: Callable, *args, **kwargs) -> Any:
|
||||
"""执行带重试的调用"""
|
||||
last_exception = None
|
||||
|
||||
for attempt in range(self.max_retries + 1):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
last_exception = e
|
||||
|
||||
if attempt < self.max_retries:
|
||||
delay = self._calculate_delay(attempt)
|
||||
ProLogger.warn("retry", f"第 {attempt + 1} 次重试,等待 {delay:.1f}s: {e}")
|
||||
time.sleep(delay)
|
||||
|
||||
raise last_exception
|
||||
|
||||
def _calculate_delay(self, attempt: int) -> float:
|
||||
"""计算退避延迟"""
|
||||
delay = self.initial_delay * (self.backoff_factor ** attempt)
|
||||
jitter = random.uniform(0, delay * 0.1)
|
||||
return delay + jitter
|
||||
Reference in New Issue
Block a user