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::role::PluginRole;
11use crate::rpc::RpcRegistrar;
12
13/// What every plugin receives in [`Plugin::boot`](crate::Plugin::boot).
14///
15/// All fields are cheaply cloneable (`Arc` or `Receiver`).
16#[derive(Clone)]
17pub struct PluginContext {
18    /// Which process this plugin instance is booting in (phase 79).
19    ///
20    /// In the **master** the `executor` is a
21    /// [`NoopExecutor`](crate::NoopExecutor) (no PHP); in a **worker** it
22    /// dispatches into that worker's PHP runtime. A [`Placement::Both`] plugin
23    /// branches on this; single-placement plugins can ignore it.
24    ///
25    /// [`Placement::Both`]: crate::Placement::Both
26    pub role: PluginRole,
27
28    /// Send work to a PHP worker.
29    ///
30    /// Valid only when [`role`](Self::role) is [`PluginRole::Worker`]; in the
31    /// master it is a [`NoopExecutor`](crate::NoopExecutor) whose methods return
32    /// `Err`.
33    pub executor: Arc<dyn Executor>,
34
35    /// Fires `true` when the server is shutting down.
36    pub shutdown: watch::Receiver<bool>,
37
38    /// Register RPC method handlers. `None` if not available.
39    pub rpc_registrar: Option<Arc<dyn RpcRegistrar>>,
40
41    /// Register health checks. `None` if not available.
42    pub health_registry: Option<Arc<dyn HealthRegistry>>,
43
44    /// Register metrics. `None` if not available.
45    pub metrics_registry: Option<Arc<dyn MetricsRegistry>>,
46}