Skip to main content

ek_core/
lifecycle.rs

1//! 生命周期与服务改版的事件类型串(宿主「说话」的全部通道,零日志)。
2//!
3//! 0.3.0 拆自原 log_plugin.rs:宿主不携带任何日志类型、不内置日志插件 ——
4//! 它想说的话全部是**结构化事件**:
5//! - `ePlugUp` / `ePlugUp.<名>`:插件上线(载荷 [`crate::service::PlugNotice`] / 版本串)
6//! - `ePlugDown` / `ePlugDown.<名>`:正常摘除(载荷同上;宿主整体 close 不发逐插件事件,防事件风暴)
7//! - `ePlugQDown.<名>`:熔断检疫定向广播(worker 自发;Q=quarantine,无载荷)
8//! - `eSrvChg` / `eSrvChg.<名>`:服务目录改版(载荷同上)
9//!
10//! 运维诊断文本(邮箱溢出/panic 累计/close 超时)只走 `stderr`,不进总线、不定义任何类型。
11//! 三族旁系(`ePlugDown` / `ePlugDown.<名>` / `ePlugQDown.<名>`)语义各别,严禁合并。
12//!
13//! 业务日志与宿主无关:谁想记日志谁自己 `ctx.put` 自己的载荷(业务链上用
14//! `ek-data` 的 `LogData` 到 `"eLog"` 键),core 全程不在场。
15
16/// 插件上线固定键(载荷 [`crate::service::PlugNotice`])。
17pub const EVENT_PLUG_UP: &str = "ePlugUp";
18/// 插件上线定向键(载荷:版本串)。
19pub const EVENT_PLUG_UP_PREFIX: &str = "ePlugUp.";
20/// 插件正常摘除固定键(载荷 [`crate::service::PlugNotice`])。
21pub const EVENT_PLUG_DOWN: &str = "ePlugDown";
22/// 插件正常摘除定向键(载荷:版本串)。正常摘除才用;宿主整体 close 不发。
23pub const EVENT_PLUG_DOWN_EVENT_PREFIX: &str = "ePlugDown.";
24/// 熔断检疫定向广播键(worker 自发;Q=quarantine,无载荷)。
25pub const EVENT_PLUG_DOWN_PREFIX: &str = "ePlugQDown.";
26/// 服务目录改版固定键(载荷 [`crate::service::PlugNotice`])。
27pub const EVENT_SRV_CHG: &str = "eSrvChg";
28/// 服务目录改版定向键(载荷:版本串)。
29pub const EVENT_SRV_CHG_PREFIX: &str = "eSrvChg.";
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    /// 固定键不带点(可用于终寻),定向键以点结尾(组合面);三族旁系互异。
36    #[test]
37    fn lifecycle_keys_shape() {
38        assert!(!EVENT_PLUG_UP.ends_with('.'));
39        assert!(EVENT_PLUG_UP_PREFIX.ends_with('.'));
40        assert!(!EVENT_PLUG_DOWN.ends_with('.'));
41        assert!(EVENT_PLUG_DOWN_EVENT_PREFIX.ends_with('.'));
42        assert!(EVENT_PLUG_DOWN_PREFIX.ends_with('.'));
43        assert_ne!(EVENT_PLUG_DOWN_EVENT_PREFIX, EVENT_PLUG_DOWN_PREFIX);
44        assert!(!EVENT_SRV_CHG.ends_with('.'));
45        assert!(EVENT_SRV_CHG_PREFIX.ends_with('.'));
46        assert!(EVENT_SRV_CHG.starts_with("eSrvChg"));
47        assert!(EVENT_PLUG_UP.starts_with("ePlugUp"));
48        assert!(EVENT_PLUG_DOWN.starts_with("ePlugDown"));
49        assert!(EVENT_PLUG_DOWN_PREFIX.starts_with("ePlugQDown."));
50    }
51}