pub struct Scheduler { /* private fields */ }Expand description
Tokio-based scheduler that fires prompt submissions on a cron-like interval.
The scheduler holds a collection of ScheduledPrompts and a sender end
of the pipeline’s input channel. Call Scheduler::spawn to start the
background task.
The scheduler checks the current wall-clock time once per minute and fires every matching prompt.
§Thread Safety
Scheduler is Send + Sync and is typically shared as Arc<Scheduler>.
The internal prompt list is guarded by a [RwLock] so that prompts can be
added and removed without stopping the background task.
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn new(tx: Sender<PromptRequest>) -> Self
pub fn new(tx: Sender<PromptRequest>) -> Self
Sourcepub async fn add(
&self,
prompt: ScheduledPrompt,
) -> Result<String, OrchestratorError>
pub async fn add( &self, prompt: ScheduledPrompt, ) -> Result<String, OrchestratorError>
Register a ScheduledPrompt.
Returns the assigned id (a UUID v4 string) so callers can reference
it later with Scheduler::remove or through the web API.
§Errors
Returns OrchestratorError::ConfigError if the prompt is disabled
and thus would never fire. Disabled prompts can be added — they are
accepted but will not emit requests until re-enabled (e.g. via the web API).
§Panics
This function does not panic.
Sourcepub async fn remove(&self, id: &str) -> bool
pub async fn remove(&self, id: &str) -> bool
Remove the scheduled prompt with the given id.
Returns true if a prompt with that ID existed and was removed, false
if no matching ID was found.
§Panics
This function does not panic.
Sourcepub async fn list(&self) -> Vec<ScheduledPrompt>
pub async fn list(&self) -> Vec<ScheduledPrompt>
Return a snapshot of all registered prompts (including disabled ones).
§Panics
This function does not panic.
Sourcepub async fn set_enabled(&self, id: &str, enabled: bool) -> bool
pub async fn set_enabled(&self, id: &str, enabled: bool) -> bool
Enable or disable a scheduled prompt by ID.
Returns true when the prompt was found and updated.
§Panics
This function does not panic.
Sourcepub fn spawn(self: &Arc<Self>) -> JoinHandle<()>
pub fn spawn(self: &Arc<Self>) -> JoinHandle<()>
Spawn the background scheduler task and return its [JoinHandle].
The task loops forever, sleeping until the next minute boundary, then
submitting all matching prompts. It stops when the handle is dropped
or [JoinHandle::abort] is called.
§Panics
The spawned task does not panic; any submission errors are logged and skipped.
Auto Trait Implementations§
impl !Freeze for Scheduler
impl !RefUnwindSafe for Scheduler
impl Send for Scheduler
impl Sync for Scheduler
impl Unpin for Scheduler
impl UnsafeUnpin for Scheduler
impl UnwindSafe for Scheduler
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<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request