pub struct LearningSink { /* private fields */ }Expand description
Learning sink - triggers offline learning when events arrive.
Uses spawn_blocking internally to run synchronous LearningStore::run_offline_learning
without blocking the async runtime.
§Trigger Integration
By default, learning runs on every event (AlwaysTrigger).
Use with_trigger() to customize when learning runs:
ⓘ
let sink = LearningSink::new(path, 20)
.with_trigger(TriggerBuilder::every_n_episodes(10));Implementations§
Source§impl LearningSink
impl LearningSink
Sourcepub fn new(learning_path: PathBuf, max_sessions: usize) -> Self
pub fn new(learning_path: PathBuf, max_sessions: usize) -> Self
Create a new learning sink.
By default, runs learning on every event (AlwaysTrigger).
§Arguments
learning_path- Path to learning data directorymax_sessions- Maximum sessions to analyze
Sourcepub fn with_trigger(self, trigger: Arc<dyn TrainTrigger>) -> Self
pub fn with_trigger(self, trigger: Arc<dyn TrainTrigger>) -> Self
Set a custom trigger for controlling when learning runs.
§Example
ⓘ
use swarm_engine_core::learn::TriggerBuilder;
// Run learning every 10 events
let sink = LearningSink::new(path, 20)
.with_trigger(TriggerBuilder::every_n_episodes(10));
// Run learning every 5 minutes OR when 50 events accumulated
let sink = LearningSink::new(path, 20)
.with_trigger(Arc::new(OrTrigger::new(vec![
TriggerBuilder::every_minutes(5),
TriggerBuilder::every_n_episodes(50),
])));Sourcepub fn learning_path(&self) -> &PathBuf
pub fn learning_path(&self) -> &PathBuf
Get the learning path.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Get the current event count.
Trait Implementations§
Source§impl EventSink for LearningSink
impl EventSink for LearningSink
Auto Trait Implementations§
impl Freeze for LearningSink
impl !RefUnwindSafe for LearningSink
impl Send for LearningSink
impl Sync for LearningSink
impl Unpin for LearningSink
impl !UnwindSafe for LearningSink
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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