bext_plugin_api/lifecycle.rs
1//! Lifecycle plugin trait for hooks that fire at server start, stop, deploy,
2//! and other key events. All methods use JSON strings for WASM ABI compatibility.
3
4/// A plugin that receives notifications at key server lifecycle points.
5///
6/// **Designed for both compile-time and WASM execution.** All methods
7/// receive and return JSON strings for ABI compatibility. Lifecycle hooks
8/// fire asynchronously after the response is sent — they must not block
9/// the request path.
10///
11/// WASM plugins: fuel budgets are enforced per call (see `types::fuel`).
12pub trait LifecyclePlugin: Send + Sync {
13 /// Unique identifier.
14 fn name(&self) -> &str;
15
16 /// Execution order among lifecycle plugins. Lower runs first.
17 fn priority(&self) -> u32 {
18 1000
19 }
20
21 /// Called once when the server starts, after all subsystems are initialized.
22 ///
23 /// `config_json` contains this plugin's config section from bext.config.toml.
24 fn on_server_start(&self, _config_json: &str) -> Result<(), String> {
25 Ok(())
26 }
27
28 /// Called when the server is shutting down gracefully.
29 fn on_server_stop(&self) -> Result<(), String> {
30 Ok(())
31 }
32
33 /// Called after a request has been fully processed and the response sent.
34 ///
35 /// `event_json` contains: path, method, status, cache_status,
36 /// render_time_us, tenant_id, site_id, encoding, is_bot.
37 fn on_request_complete(&self, _event_json: &str) -> Result<(), String> {
38 Ok(())
39 }
40
41 /// Called after a new entry is stored in the ISR cache.
42 fn on_cache_write(&self, _key: &str, _tags_json: &str) -> Result<(), String> {
43 Ok(())
44 }
45
46 /// Called when ISR cache entries are invalidated.
47 fn on_cache_invalidate(&self, _pattern: &str, _count: u32) -> Result<(), String> {
48 Ok(())
49 }
50
51 /// Called after a successful JSC pool reload (bundle updated).
52 fn on_reload(&self) -> Result<(), String> {
53 Ok(())
54 }
55
56 /// Cleanup before plugin unload. Release resources here.
57 fn cleanup(&self) -> Result<(), String> {
58 Ok(())
59 }
60}