folk-api 0.3.0

Plugin contract for the Folk PHP application server
Documentation
//! Dependencies handed to a plugin at boot.

use std::sync::Arc;

use tokio::sync::watch;

use crate::executor::Executor;
use crate::health::HealthRegistry;
use crate::metrics::MetricsRegistry;
use crate::role::PluginRole;
use crate::rpc::RpcRegistrar;

/// What every plugin receives in [`Plugin::boot`](crate::Plugin::boot).
///
/// All fields are cheaply cloneable (`Arc` or `Receiver`).
#[derive(Clone)]
pub struct PluginContext {
    /// Which process this plugin instance is booting in (phase 79).
    ///
    /// In the **master** the `executor` is a
    /// [`NoopExecutor`](crate::NoopExecutor) (no PHP); in a **worker** it
    /// dispatches into that worker's PHP runtime. A [`Placement::Both`] plugin
    /// branches on this; single-placement plugins can ignore it.
    ///
    /// [`Placement::Both`]: crate::Placement::Both
    pub role: PluginRole,

    /// Send work to a PHP worker.
    ///
    /// Valid only when [`role`](Self::role) is
    /// [`PluginRole::Worker`](crate::PluginRole::Worker); in the master it is a
    /// [`NoopExecutor`](crate::NoopExecutor) whose methods return `Err`.
    pub executor: Arc<dyn Executor>,

    /// Fires `true` when the server is shutting down.
    pub shutdown: watch::Receiver<bool>,

    /// Register RPC method handlers. `None` if not available.
    pub rpc_registrar: Option<Arc<dyn RpcRegistrar>>,

    /// Register health checks. `None` if not available.
    pub health_registry: Option<Arc<dyn HealthRegistry>>,

    /// Register metrics. `None` if not available.
    pub metrics_registry: Option<Arc<dyn MetricsRegistry>>,
}