pub struct FireForgetSchedulerFuture<TID, WID, Data, Launcher>where
TID: Clone + PartialEq,
WID: Clone + PartialEq,
Launcher: Fn(TID, WID, Data),{
command_sender: FireForgetScheduler<TID, WID, Data>,
command_receiver: Receiver<Command<TID, WID, Data>>,
scheduled: VecDeque<ScheduledTask<TID, WID, Data>>,
running: Vec<RunningTask<TID, WID>>,
timeouts: DelayQueue<TimedOutTask<TID, WID>>,
launcher: Launcher,
max_running_same_task: usize,
timeout: Duration,
}
Expand description
Schedule for fire-forget tasks
Each task has an ID (TID) and can be launched onto a worker identified with an ID (WID). Launching is defined by a closure (Launcher), which also accepts additional data (Data). Multiple instances of task with same TID, but different WID may be running in parallel. Launcher must be quick and non-blocking.
When task is scheduled, it’s queued. When it’s finally launched, a timeout is started. Until it runs out or task is declared complete it’s considered running and it consumes parallel task execution limits. Finishing with timeout doesn’t make task completed and other queued instances with same TID, but different WID may be run. Timed out instances are considered failed and aren’t rescheduled. Finishing by declaration task completion cancels all task instances with the same TID.
Scheduling tasks and declaring them complete is possible with FireForgetScheduler
.
The scheduler is a future that never resolves, it’s used only to drive itself on executor. It requires a valid Tokio context.
Fields§
§command_sender: FireForgetScheduler<TID, WID, Data>
§command_receiver: Receiver<Command<TID, WID, Data>>
§scheduled: VecDeque<ScheduledTask<TID, WID, Data>>
§running: Vec<RunningTask<TID, WID>>
§timeouts: DelayQueue<TimedOutTask<TID, WID>>
§launcher: Launcher
§max_running_same_task: usize
§timeout: Duration
Implementations§
source§impl<TID, WID, Data, Launcher> FireForgetSchedulerFuture<TID, WID, Data, Launcher>where
TID: Clone + PartialEq,
WID: Clone + PartialEq,
Launcher: Fn(TID, WID, Data),
impl<TID, WID, Data, Launcher> FireForgetSchedulerFuture<TID, WID, Data, Launcher>where TID: Clone + PartialEq, WID: Clone + PartialEq, Launcher: Fn(TID, WID, Data),
sourcepub fn new(config: &FireForgetSchedulerConfig, launcher: Launcher) -> Self
pub fn new(config: &FireForgetSchedulerConfig, launcher: Launcher) -> Self
Launcher controls how tasks will be started. It must be quick and non-blocking.
pub fn scheduler(&self) -> FireForgetScheduler<TID, WID, Data>
fn schedule(&mut self, task: ScheduledTask<TID, WID, Data>)
fn declare_completed(&mut self, task: TID)
fn declare_timed_out(&mut self, timed_out: TimedOutTask<TID, WID>)
fn try_run_scheduled(&mut self)
fn pop_next_runnable_task(&mut self) -> Option<ScheduledTask<TID, WID, Data>>
fn task_run_count(&self, scheduled: &ScheduledTask<TID, WID, Data>) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<TID, WID, Data, Launcher> !RefUnwindSafe for FireForgetSchedulerFuture<TID, WID, Data, Launcher>
impl<TID, WID, Data, Launcher> Send for FireForgetSchedulerFuture<TID, WID, Data, Launcher>where Data: Send, Launcher: Send, TID: Send, WID: Send,
impl<TID, WID, Data, Launcher> Sync for FireForgetSchedulerFuture<TID, WID, Data, Launcher>where Data: Send + Sync, Launcher: Sync, TID: Send + Sync, WID: Send + Sync,
impl<TID, WID, Data, Launcher> Unpin for FireForgetSchedulerFuture<TID, WID, Data, Launcher>where Data: Unpin, Launcher: Unpin, TID: Unpin, WID: Unpin,
impl<TID, WID, Data, Launcher> !UnwindSafe for FireForgetSchedulerFuture<TID, WID, Data, Launcher>
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<T> FutureExt for Twhere
T: Future + ?Sized,
impl<T> FutureExt for Twhere T: Future + ?Sized,
§fn map<U, F>(self, f: F) -> Map<Self, F>where
F: FnOnce(Self::Output) -> U,
Self: Sized,
fn map<U, F>(self, f: F) -> Map<Self, F>where F: FnOnce(Self::Output) -> U, Self: Sized,
§fn map_into<U>(self) -> MapInto<Self, U>where
Self::Output: Into<U>,
Self: Sized,
fn map_into<U>(self) -> MapInto<Self, U>where Self::Output: Into<U>, Self: Sized,
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
Self: Sized,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where F: FnOnce(Self::Output) -> Fut, Fut: Future, Self: Sized,
f
. Read more§fn left_future<B>(self) -> Either<Self, B>where
B: Future<Output = Self::Output>,
Self: Sized,
fn left_future<B>(self) -> Either<Self, B>where B: Future<Output = Self::Output>, Self: Sized,
§fn right_future<A>(self) -> Either<A, Self>where
A: Future<Output = Self::Output>,
Self: Sized,
fn right_future<A>(self) -> Either<A, Self>where A: Future<Output = Self::Output>, Self: Sized,
§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where Self: Sized,
§fn flatten(self) -> Flatten<Self>where
Self::Output: Future,
Self: Sized,
fn flatten(self) -> Flatten<Self>where Self::Output: Future, Self: Sized,
§fn flatten_stream(self) -> FlattenStream<Self>where
Self::Output: Stream,
Self: Sized,
fn flatten_stream(self) -> FlattenStream<Self>where Self::Output: Stream, Self: Sized,
§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnOnce(&Self::Output),
Self: Sized,
fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: FnOnce(&Self::Output), Self: Sized,
§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where Self: Sized + UnwindSafe,
§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read more§fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where
Self: Sized + Send + 'a,
fn boxed<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where Self: Sized + Send + 'a,
§fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where
Self: Sized + 'a,
fn boxed_local<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where Self: Sized + 'a,
§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.§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> 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<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere F: Future,
§type IntoFuture = F
type IntoFuture = F
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
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
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
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
impl<Fut> TryFutureExt for Futwhere Fut: TryFuture + ?Sized,
§fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where Self::Ok: Sink<Item, Error = Self::Error>, Self: Sized,
Sink
]. Read more