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() -> ScriptRegistry
pub fn new() -> ScriptRegistry
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() -> ScriptRegistry
pub fn from_inventory() -> ScriptRegistry
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<'_>, ChrononError>
pub fn get_or_err( &self, name: &str, ) -> Result<ScriptDescriptorRef<'_>, ChrononError>
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.
Trait Implementations§
Source§impl Default for ScriptRegistry
impl Default for ScriptRegistry
Source§fn default() -> ScriptRegistry
fn default() -> ScriptRegistry
Auto Trait Implementations§
impl Freeze for ScriptRegistry
impl RefUnwindSafe for ScriptRegistry
impl Send for ScriptRegistry
impl Sync for ScriptRegistry
impl Unpin for ScriptRegistry
impl UnsafeUnpin for ScriptRegistry
impl UnwindSafe for ScriptRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more