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:
49
store/@{FutureOSS}/plugin-loader-pro/fallback/handler.py
Normal file
49
store/@{FutureOSS}/plugin-loader-pro/fallback/handler.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""降级处理器"""
|
||||
from typing import Callable, Any, Optional
|
||||
from ..utils.logger import ProLogger
|
||||
|
||||
|
||||
class FallbackStrategy:
|
||||
"""降级策略枚举"""
|
||||
RETURN_DEFAULT = "return_default"
|
||||
RETURN_CACHE = "return_cache"
|
||||
RETURN_NULL = "return_null"
|
||||
CALL_ALTERNATIVE = "call_alternative"
|
||||
|
||||
|
||||
class FallbackHandler:
|
||||
"""降级处理器"""
|
||||
|
||||
def __init__(self, strategy: str = FallbackStrategy.RETURN_NULL,
|
||||
default_value: Any = None,
|
||||
alternative_func: Callable = None):
|
||||
self.strategy = strategy
|
||||
self.default_value = default_value
|
||||
self.alternative_func = alternative_func
|
||||
self._cache = {}
|
||||
|
||||
def execute(self, func: Callable, plugin_name: str, *args, **kwargs) -> Any:
|
||||
"""执行降级逻辑"""
|
||||
try:
|
||||
result = func(*args, **kwargs)
|
||||
self._cache[plugin_name] = result
|
||||
return result
|
||||
except Exception as e:
|
||||
ProLogger.warn("fallback", f"插件 {plugin_name} 执行失败,触发降级: {e}")
|
||||
return self._apply_fallback(plugin_name)
|
||||
|
||||
def _apply_fallback(self, plugin_name: str) -> Any:
|
||||
"""应用降级策略"""
|
||||
if self.strategy == FallbackStrategy.RETURN_DEFAULT:
|
||||
return self.default_value
|
||||
elif self.strategy == FallbackStrategy.RETURN_CACHE:
|
||||
return self._cache.get(plugin_name)
|
||||
elif self.strategy == FallbackStrategy.RETURN_NULL:
|
||||
return None
|
||||
elif self.strategy == FallbackStrategy.CALL_ALTERNATIVE:
|
||||
if self.alternative_func:
|
||||
try:
|
||||
return self.alternative_func()
|
||||
except Exception as e:
|
||||
ProLogger.error("fallback", f"备选方案也失败了: {e}")
|
||||
return None
|
||||
Reference in New Issue
Block a user