pub trait Plugin:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &'static str;
fn boot<'life0, 'async_trait>(
&'life0 mut self,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn rpc_methods(&self) -> Vec<RpcMethodDef> { ... }
fn placement(&self) -> Placement { ... }
fn runs_in_every_pool(&self) -> bool { ... }
}Expand description
Lifecycle of a Folk plugin.
At server startup, plugins are booted in registration order. At shutdown,
they are stopped in reverse order. A plugin that holds long-running tasks
should consider implementing crate::ServerPlugin instead — the wrapper
handles the boilerplate of spawning, holding handles, and joining.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable plugin name. Conventionally lowercase, single-word: "http",
"jobs", "metrics". Used for log scoping, health/metric labels,
and config-section routing in custom builds.
Sourcefn boot<'life0, 'async_trait>(
&'life0 mut self,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn boot<'life0, 'async_trait>(
&'life0 mut self,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Called once at server startup. Register RPC methods, health checks,
and metrics via ctx, then spawn background tasks. Returning Err
is fatal: the server aborts startup.
Provided Methods§
Sourcefn rpc_methods(&self) -> Vec<RpcMethodDef>
fn rpc_methods(&self) -> Vec<RpcMethodDef>
Optional: the RPC methods this plugin exposes. Used for advertising
(e.g., folk admin list-methods). Default is empty.
Sourcefn placement(&self) -> Placement
fn placement(&self) -> Placement
Where this plugin runs in the fork-after-warm model (phase 79).
The core boots the plugin only in the process(es) named here. The
default is Placement::WorkerOnly — the common case (HTTP/gRPC/jobs
dispatch PHP and live in workers). Master-only plugins (supervisors, the
metrics scrape server) override this to Placement::MasterOnly.
Sourcefn runs_in_every_pool(&self) -> bool
fn runs_in_every_pool(&self) -> bool
Whether this plugin must be booted in every worker pool, not just its own (phase 85).
Default false: a worker-plugin runs only in its pool (a dedicated
[<plugin>].workers pool, or the shared pool). true means the plugin
exposes a cross-cutting capability that other pools call into — e.g.
jobs enqueue (jobs.push), invoked from an HTTP handler running in a
separate http pool. Because Folk’s RPC is process-local (zero-IPC), the
only way that call resolves is for the jobs plugin to also be present in
the http pool. Such a plugin branches on
PoolContext::primary to do its heavy work
(run consumers) only in its owning pool and stay push-only elsewhere.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".