pub struct ScriptRegistry { /* private fields */ }Expand description
In-memory script registry with optional link-time inventory discovery.
Populated at boot via Self::from_inventory / Self::register_from_inventory (from
#[chronon::script]) or manual Self::register calls. Read by the executor when a run is
claimed.
In Mode 2 (coordinator + worker), scripts must be registered on worker binaries —
that is where handlers execute. Prefer ChrononBuilder::auto_registry() so inventory is
collected automatically.
§Examples
Empty registry:
use chronon_executor::ScriptRegistry;
let registry = ScriptRegistry::new();
assert!(registry.is_empty());Explicit register (daemon-style, without the macro):
use chronon_core::{Result, ScriptContext};
use chronon_executor::{ScriptDescriptor, ScriptRegistry};
fn noop(
_ctx: Box<dyn ScriptContext>,
_params: serde_json::Value,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<()>> + Send>> {
Box::pin(async { Ok(()) })
}
let mut registry = ScriptRegistry::new();
registry.register(ScriptDescriptor::new("daemon-noop", noop));
assert!(registry.contains("daemon-noop"));
assert_eq!(registry.len(), 1);Implementations§
Source§impl ScriptRegistry
impl ScriptRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty registry with no registered scripts.
§Examples
use chronon_executor::ScriptRegistry;
let registry = ScriptRegistry::new();
assert!(registry.is_empty());Sourcepub fn from_inventory() -> Self
pub fn from_inventory() -> Self
Populate from all #[chronon::script] descriptors linked into the binary.
Equivalent to ChrononBuilder::auto_registry() wiring. Prefer this on Mode 2 workers.
Sourcepub fn register_from_inventory(&mut self)
pub fn register_from_inventory(&mut self)
Register every script descriptor collected via link-time inventory.
Sourcepub fn register(&mut self, desc: ScriptDescriptor)
pub fn register(&mut self, desc: ScriptDescriptor)
Inserts or replaces a script descriptor keyed by ScriptDescriptor::name.
Duplicate names overwrite the previous handler without error.
Sourcepub fn get(&self, name: &str) -> Option<ScriptDescriptorRef<'_>>
pub fn get(&self, name: &str) -> Option<ScriptDescriptorRef<'_>>
Returns a borrowed view of the script named name, if registered.
Sourcepub fn get_or_err(&self, name: &str) -> Result<ScriptDescriptorRef<'_>>
pub fn get_or_err(&self, name: &str) -> Result<ScriptDescriptorRef<'_>>
Like Self::get, but returns ChrononError::ScriptNotFound when absent.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Returns true when a script with the given name is registered.
Sourcepub fn list(&self) -> Vec<ScriptDescriptorRef<'_>>
pub fn list(&self) -> Vec<ScriptDescriptorRef<'_>>
Returns all registered scripts sorted by name.