pub trait ArclyPlugin:
Send
+ Sync
+ 'static {
// Required method
fn name(&self) -> &'static str;
// Provided methods
fn on_init<'a>(
&'a mut self,
ctx: &'a mut ArclyPluginContext,
) -> BoxFuture<'a, Result<(), PluginError>> { ... }
fn on_draining<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>> { ... }
fn on_start<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>> { ... }
fn on_shutdown<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>> { ... }
}Expand description
Plugin lifecycle.
All three hooks receive the framework’s frozen DI container as a
&'static ref (after init completes), so background tasks and shutdown
drain routines can resolve injected services with zero locks. The init
hook receives the mutable ArclyPluginContext, through which the
plugin can provide<T> new singletons into the container before it
freezes.
Required Methods§
Provided Methods§
Sourcefn on_init<'a>(
&'a mut self,
ctx: &'a mut ArclyPluginContext,
) -> BoxFuture<'a, Result<(), PluginError>>
fn on_init<'a>( &'a mut self, ctx: &'a mut ArclyPluginContext, ) -> BoxFuture<'a, Result<(), PluginError>>
Pre-bind. Register providers, routes, interceptors, openapi mutators.
The container is built AFTER every plugin’s on_init returns.
Sourcefn on_draining<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>>
fn on_draining<'a>( &'a self, container: &'static FrozenDiContainer, ) -> BoxFuture<'a, Result<(), PluginError>>
Drain started. Fired as soon as a shutdown signal is received,
concurrently with the HTTP in-flight drain (it does not delay the
listener closing). Stop accepting new work here — pause message-queue
consumers, schedulers, pollers — so plugin workloads quiesce while
HTTP connections drain. Cleanup itself belongs in on_shutdown.
Sourcefn on_start<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>>
fn on_start<'a>( &'a self, container: &'static FrozenDiContainer, ) -> BoxFuture<'a, Result<(), PluginError>>
Post-bind. Listener is live and accepting. Background tasks spawn
here. container resolves any provider — including ones the plugin
itself registered in on_init.
Sourcefn on_shutdown<'a>(
&'a self,
container: &'static FrozenDiContainer,
) -> BoxFuture<'a, Result<(), PluginError>>
fn on_shutdown<'a>( &'a self, container: &'static FrozenDiContainer, ) -> BoxFuture<'a, Result<(), PluginError>>
Graceful shutdown. Invoked after the HTTP server has stopped
accepting new connections and all in-flight requests have drained.
Wrapped by App in a per-plugin timeout (default 5s, configurable
via LaunchConfig::drain_budget) so a hung plugin can never wedge
the process or starve other plugins’ shutdown.
Do not block. The timeout can only cancel the future at an
.await point — a synchronous spin or blocking syscall here pins a
runtime worker thread until it returns. Use spawn_blocking for
unavoidable blocking cleanup.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".