pub struct PoolManager { /* private fields */ }Expand description
Manages the pool server process and connections
Implementations§
Source§impl PoolManager
impl PoolManager
Sourcepub fn calculate_heap_size(max_concurrency: usize) -> usize
pub fn calculate_heap_size(max_concurrency: usize) -> usize
Calculate heap size based on concurrency level.
Formula: BASE_HEAP_MB + ((max_concurrency / CONCURRENCY_DIVISOR) * HEAP_INCREMENT_PER_DIVISOR_MB) Result is capped at MAX_HEAP_MB.
This scales memory allocation with expected load while maintaining a reasonable minimum.
Sourcepub fn format_return_value(value: Option<Value>) -> String
pub fn format_return_value(value: Option<Value>) -> String
Format a result value from the pool response into a string.
If the value is already a string, returns it directly. Otherwise, serializes it to JSON.
Sourcepub fn parse_success_response(response: PoolResponse) -> ScriptResult
pub fn parse_success_response(response: PoolResponse) -> ScriptResult
Parse a successful pool response into a ScriptResult.
Converts logs from PoolLogEntry to LogEntry and extracts the return value.
Sourcepub fn parse_error_response(response: PoolResponse) -> PluginError
pub fn parse_error_response(response: PoolResponse) -> PluginError
Parse a failed pool response into a PluginError.
Extracts error details and converts logs for inclusion in the error payload.
Sourcepub fn parse_pool_response(
response: PoolResponse,
) -> Result<ScriptResult, PluginError>
pub fn parse_pool_response( response: PoolResponse, ) -> Result<ScriptResult, PluginError>
Parse a pool response into either a success result or an error.
This is the main entry point for response parsing, dispatching to either parse_success_response or parse_error_response based on the success flag.
Sourcepub fn parse_health_result(result: &Value) -> ParsedHealthResult
pub fn parse_health_result(result: &Value) -> ParsedHealthResult
Parse health check result JSON into individual fields.
Extracts status, uptime, memory usage, pool stats, and success rate from the nested JSON structure returned by the pool server.
Sourcepub fn with_socket_path(socket_path: String) -> Self
pub fn with_socket_path(socket_path: String) -> Self
Create a new PoolManager with custom socket path
Sourcepub async fn is_initialized(&self) -> bool
pub async fn is_initialized(&self) -> bool
Check if the pool manager has been initialized.
This is useful for health checks to determine if the plugin pool is expected to be running.
Sourcepub async fn ensure_started(&self) -> Result<(), PluginError>
pub async fn ensure_started(&self) -> Result<(), PluginError>
Start the pool server if not already running
Sourcepub async fn execute_plugin(
&self,
plugin_id: String,
compiled_code: Option<String>,
plugin_path: Option<String>,
params: Value,
headers: Option<HashMap<String, Vec<String>>>,
socket_path: String,
http_request_id: Option<String>,
timeout_secs: Option<u64>,
route: Option<String>,
config: Option<Value>,
method: Option<String>,
query: Option<Value>,
) -> Result<ScriptResult, PluginError>
pub async fn execute_plugin( &self, plugin_id: String, compiled_code: Option<String>, plugin_path: Option<String>, params: Value, headers: Option<HashMap<String, Vec<String>>>, socket_path: String, http_request_id: Option<String>, timeout_secs: Option<u64>, route: Option<String>, config: Option<Value>, method: Option<String>, query: Option<Value>, ) -> Result<ScriptResult, PluginError>
Execute a plugin via the pool
Sourcepub fn is_dead_server_error(err: &PluginError) -> bool
pub fn is_dead_server_error(err: &PluginError) -> bool
Check if an error indicates the pool server is dead and needs restart
Sourcepub async fn precompile_plugin(
&self,
plugin_id: String,
plugin_path: Option<String>,
source_code: Option<String>,
) -> Result<String, PluginError>
pub async fn precompile_plugin( &self, plugin_id: String, plugin_path: Option<String>, source_code: Option<String>, ) -> Result<String, PluginError>
Precompile a plugin
Sourcepub async fn cache_compiled_code(
&self,
plugin_id: String,
compiled_code: String,
) -> Result<(), PluginError>
pub async fn cache_compiled_code( &self, plugin_id: String, compiled_code: String, ) -> Result<(), PluginError>
Cache compiled code in the pool
Sourcepub async fn invalidate_plugin(
&self,
plugin_id: String,
) -> Result<(), PluginError>
pub async fn invalidate_plugin( &self, plugin_id: String, ) -> Result<(), PluginError>
Invalidate a cached plugin
pub async fn health_check(&self) -> Result<HealthStatus, PluginError>
Sourcepub async fn ensure_healthy(&self) -> Result<bool, PluginError>
pub async fn ensure_healthy(&self) -> Result<bool, PluginError>
Check health and restart if unhealthy
Sourcepub async fn restart(&self) -> Result<(), PluginError>
pub async fn restart(&self) -> Result<(), PluginError>
Force restart the pool server (public API - acquires lock)
Sourcepub fn circuit_state(&self) -> CircuitState
pub fn circuit_state(&self) -> CircuitState
Get current circuit breaker state for monitoring
Sourcepub fn avg_response_time_ms(&self) -> u32
pub fn avg_response_time_ms(&self) -> u32
Get average response time in ms (for monitoring)
Sourcepub fn is_recovering(&self) -> bool
pub fn is_recovering(&self) -> bool
Check if currently in recovery mode
Sourcepub fn recovery_allowance_percent(&self) -> u32
pub fn recovery_allowance_percent(&self) -> u32
Get current recovery allowance percentage (0-100)
Sourcepub async fn shutdown(&self) -> Result<(), PluginError>
pub async fn shutdown(&self) -> Result<(), PluginError>
Shutdown the pool server gracefully
Trait Implementations§
Source§impl Default for PoolManager
impl Default for PoolManager
Auto Trait Implementations§
impl !Freeze for PoolManager
impl !RefUnwindSafe for PoolManager
impl Send for PoolManager
impl Sync for PoolManager
impl Unpin for PoolManager
impl !UnwindSafe for PoolManager
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more