pub struct CommonServiceTask { /* private fields */ }Implementations§
Source§impl CommonServiceTask
impl CommonServiceTask
Sourcepub fn new(interval: Duration, task: impl ServiceTask + 'static) -> Self
pub fn new(interval: Duration, task: impl ServiceTask + 'static) -> Self
Creates a new CommonServiceTask that wraps a single task implementation. This is useful for simpler cases where only one recurring task is needed.
§Arguments
interval- Duration between task executionstask- Implementation of ServiceTask to execute
§Special Cases
- If interval is less than 1 second, task runs only once
- Task can signal completion via return value to stop service
Trait Implementations§
Source§impl BackgroundService for CommonServiceTask
impl BackgroundService for CommonServiceTask
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,
Starts the background service, executing the wrapped task at the specified interval. The service runs until one of the following conditions is met:
- Shutdown signal is received
- Task returns Some(true) indicating completion
- Interval is less than 1 second (runs once and stops)
§Arguments
shutdown- Watch channel for shutdown coordination
§Logging
- Service start is logged with task description and interval
- Each task execution is logged with elapsed time
- Task completion status is logged
§Performance Considerations
- Task execution time is measured and logged
- Long-running tasks may delay the next interval
Auto Trait Implementations§
impl Freeze for CommonServiceTask
impl !RefUnwindSafe for CommonServiceTask
impl Send for CommonServiceTask
impl Sync for CommonServiceTask
impl Unpin for CommonServiceTask
impl !UnwindSafe for CommonServiceTask
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