pub struct BackgroundTaskService { /* private fields */ }Expand description
A unified background service runner that can handle one or more named tasks.
Implementations§
Source§impl BackgroundTaskService
impl BackgroundTaskService
Sourcepub fn new(
name: &str,
interval: Duration,
tasks: Vec<(String, Box<dyn BackgroundTask>)>,
) -> Self
pub fn new( name: &str, interval: Duration, tasks: Vec<(String, Box<dyn BackgroundTask>)>, ) -> Self
Creates a new service to run multiple background tasks.
Sourcepub fn new_single(
name: &str,
interval: Duration,
task_name: &str,
task: Box<dyn BackgroundTask>,
) -> Self
pub fn new_single( name: &str, interval: Duration, task_name: &str, task: Box<dyn BackgroundTask>, ) -> Self
A convenience constructor for creating a service with a single task.
Sourcepub fn set_immediately(&mut self, immediately: bool)
pub fn set_immediately(&mut self, immediately: bool)
Set whether the service should run immediately or wait for the interval
pub fn set_initial_delay(&mut self, initial_delay: Option<Duration>)
Sourcepub fn add_task(&mut self, task_name: &str, task: Box<dyn BackgroundTask>)
pub fn add_task(&mut self, task_name: &str, task: Box<dyn BackgroundTask>)
Add a task to the service This is useful for adding tasks to the service after it has been created
pub fn name(&self) -> String
Trait Implementations§
Source§impl BackgroundService for BackgroundTaskService
impl BackgroundService for BackgroundTaskService
Source§fn start<'life0, 'async_trait>(
&'life0 self,
shutdown: ShutdownWatch,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
shutdown: ShutdownWatch,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
This function is called when the pingora server tries to start all the
services. The background service can return at anytime or wait for the
shutdown signal.Auto Trait Implementations§
impl !Freeze for BackgroundTaskService
impl !RefUnwindSafe for BackgroundTaskService
impl Send for BackgroundTaskService
impl Sync for BackgroundTaskService
impl Unpin for BackgroundTaskService
impl UnsafeUnpin for BackgroundTaskService
impl !UnwindSafe for BackgroundTaskService
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