pub struct TaskRegistry { /* private fields */ }Expand description
Registry for task implementations.
Maps task IDs to factory functions that create task instances. This enables workflow serialization: only IDs and structure are serialized, and implementations are looked up from the registry at runtime.
Important: The registry is code, not data. It contains closures and cannot be serialized. Both serialization and deserialization sides must construct the same registry by calling the same registration functions. See module docs for the recommended pattern.
Implementations§
Source§impl TaskRegistry
impl TaskRegistry
Sourcepub fn new() -> TaskRegistry
pub fn new() -> TaskRegistry
Create a new empty registry.
Sourcepub fn register<T, C>(&mut self, id: &str, codec: Arc<C>, task: T)
pub fn register<T, C>(&mut self, id: &str, codec: Arc<C>, task: T)
Register a task implementing CoreTask.
This method accepts any type implementing CoreTask, including:
- Structs with explicit
CoreTaskimplementation - Closures wrapped with
fn_task
For convenience with raw closures, use register_fn.
§Example
use sayiir_core::prelude::*;
use std::pin::Pin;
use std::future::Future;
struct DoubleTask;
impl CoreTask for DoubleTask {
type Input = u32;
type Output = u32;
type Future = Pin<Box<dyn Future<Output = Result<u32, BoxError>> + Send>>;
fn run(&self, input: u32) -> Self::Future {
Box::pin(async move { Ok(input * 2) })
}
}
// Register a struct implementing CoreTask
registry.register("struct_task", codec.clone(), DoubleTask);
// Register a closure via fn_task wrapper
registry.register("closure_task", codec.clone(), fn_task(|i: u32| async move { Ok(i * 2) }));Sourcepub fn register_with_metadata<T, C>(
&mut self,
id: &str,
codec: Arc<C>,
task: T,
metadata: TaskMetadata,
)
pub fn register_with_metadata<T, C>( &mut self, id: &str, codec: Arc<C>, task: T, metadata: TaskMetadata, )
Register a task implementing CoreTask with metadata.
Same as register, but allows attaching metadata
for timeouts, retries, and display information.
Sourcepub fn register_fn<I, O, F, Fut, C>(&mut self, id: &str, codec: Arc<C>, func: F)
pub fn register_fn<I, O, F, Fut, C>(&mut self, id: &str, codec: Arc<C>, func: F)
Sourcepub fn register_fn_with_metadata<I, O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: F,
metadata: TaskMetadata,
)
pub fn register_fn_with_metadata<I, O, F, Fut, C>( &mut self, id: &str, codec: Arc<C>, func: F, metadata: TaskMetadata, )
Register a closure as a task with metadata.
Same as register_fn, but allows attaching metadata.
Sourcepub fn register_join<O, F, Fut, C>(&mut self, id: &str, codec: Arc<C>, func: F)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
pub fn register_join<O, F, Fut, C>(&mut self, id: &str, codec: Arc<C>, func: F)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
Register a join task using a closure.
Sourcepub fn register_join_with_metadata<O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: F,
metadata: TaskMetadata,
)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
pub fn register_join_with_metadata<O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: F,
metadata: TaskMetadata,
)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
Register a join task using a closure with metadata.
Sourcepub fn get(
&self,
id: &str,
) -> Option<Box<dyn CoreTask<Output = Bytes, Future = BytesFuture, Input = Bytes> + Send + Sync>>
pub fn get( &self, id: &str, ) -> Option<Box<dyn CoreTask<Output = Bytes, Future = BytesFuture, Input = Bytes> + Send + Sync>>
Get a task by ID, creating a new instance.
Returns None if the task ID is not registered.
Sourcepub fn get_metadata(&self, id: &str) -> Option<&TaskMetadata>
pub fn get_metadata(&self, id: &str) -> Option<&TaskMetadata>
Get the metadata for a task by ID.
Returns None if the task ID is not registered.
Sourcepub fn get_with_metadata(
&self,
id: &str,
) -> Option<(Box<dyn CoreTask<Output = Bytes, Future = BytesFuture, Input = Bytes> + Send + Sync>, &TaskMetadata)>
pub fn get_with_metadata( &self, id: &str, ) -> Option<(Box<dyn CoreTask<Output = Bytes, Future = BytesFuture, Input = Bytes> + Send + Sync>, &TaskMetadata)>
Get both the task and its metadata by ID.
Returns None if the task ID is not registered.
Sourcepub fn set_metadata(&mut self, id: &str, metadata: TaskMetadata) -> bool
pub fn set_metadata(&mut self, id: &str, metadata: TaskMetadata) -> bool
Set or update the metadata for a registered task.
Returns true if the task was found and metadata updated, false otherwise.
Sourcepub fn with_codec<C>(codec: Arc<C>) -> RegistryBuilder<C>where
C: Codec,
pub fn with_codec<C>(codec: Arc<C>) -> RegistryBuilder<C>where
C: Codec,
Create a builder with a codec for ergonomic task registration.
§Example
let registry = TaskRegistry::with_codec(codec)
.register_fn("double", |i: u32| async move { Ok(i * 2) })
.register_fn("add_ten", |i: u32| async move { Ok(i + 10) })
.build();Trait Implementations§
Source§impl Default for TaskRegistry
impl Default for TaskRegistry
Source§fn default() -> TaskRegistry
fn default() -> TaskRegistry
Source§impl RegistryBehavior for TaskRegistry
impl RegistryBehavior for TaskRegistry
Source§fn maybe_register<I, O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: &Arc<F>,
)
fn maybe_register<I, O, F, Fut, C>( &mut self, id: &str, codec: Arc<C>, func: &Arc<F>, )
NoRegistry, actual registration for TaskRegistry).Source§fn maybe_register_join<O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: &Arc<F>,
)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
fn maybe_register_join<O, F, Fut, C>(
&mut self,
id: &str,
codec: Arc<C>,
func: &Arc<F>,
)where
F: Fn(BranchOutputs<C>) -> Fut + Send + Sync + 'static,
O: Send + 'static,
Fut: Future<Output = Result<O, Box<dyn Error + Send + Sync>>> + Send + 'static,
C: Codec + EncodeValue<O> + DecodeValue<NamedBranchResults> + Send + Sync + 'static,
NoRegistry, actual registration for TaskRegistry).Auto Trait Implementations§
impl Freeze for TaskRegistry
impl !RefUnwindSafe for TaskRegistry
impl Send for TaskRegistry
impl Sync for TaskRegistry
impl Unpin for TaskRegistry
impl UnsafeUnpin for TaskRegistry
impl !UnwindSafe for TaskRegistry
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.