Skip to main content

folk_api/
context.rs

1//! Dependencies handed to a plugin at boot.
2
3use std::sync::Arc;
4
5use tokio::sync::watch;
6
7use crate::executor::Executor;
8use crate::health::HealthRegistry;
9use crate::metrics::MetricsRegistry;
10use crate::rpc::RpcRegistrar;
11
12/// What every plugin receives in [`Plugin::boot`](crate::Plugin::boot).
13///
14/// All fields are cheaply cloneable (`Arc` or `Receiver`).
15#[derive(Clone)]
16pub struct PluginContext {
17    /// Send work to a PHP worker.
18    pub executor: Arc<dyn Executor>,
19
20    /// Fires `true` when the server is shutting down.
21    pub shutdown: watch::Receiver<bool>,
22
23    /// Register RPC method handlers. `None` if not available.
24    pub rpc_registrar: Option<Arc<dyn RpcRegistrar>>,
25
26    /// Register health checks. `None` if not available.
27    pub health_registry: Option<Arc<dyn HealthRegistry>>,
28
29    /// Register metrics. `None` if not available.
30    pub metrics_registry: Option<Arc<dyn MetricsRegistry>>,
31}