pub trait TaskHandler: Send + Sync {
// Required method
fn execute(
&self,
config: &Value,
) -> Pin<Box<dyn Future<Output = Result<(), SchedulerError>> + Send + '_>>;
}Expand description
Trait for types that can execute a scheduled task.
Implementations receive the per-task JSON configuration stored in
ScheduledTask::config and return Ok(()) on success or a
SchedulerError on failure. Failures are logged as warnings; the scheduler
continues running and will retry on the next due tick.
Because async trait methods in Edition 2024 require returning a pinned boxed
future for object safety, implementations must wrap their async work in
Box::pin(async move { … }).
§Example
use std::future::Future;
use std::pin::Pin;
use zeph_scheduler::{SchedulerError, TaskHandler};
struct NoopHandler;
impl TaskHandler for NoopHandler {
fn execute(
&self,
_config: &serde_json::Value,
) -> Pin<Box<dyn Future<Output = Result<(), SchedulerError>> + Send + '_>> {
Box::pin(async move { Ok(()) })
}
}Required Methods§
Sourcefn execute(
&self,
config: &Value,
) -> Pin<Box<dyn Future<Output = Result<(), SchedulerError>> + Send + '_>>
fn execute( &self, config: &Value, ) -> Pin<Box<dyn Future<Output = Result<(), SchedulerError>> + Send + '_>>
Execute the task with the provided configuration.
§Errors
Return SchedulerError::TaskFailed (or any other variant) to indicate
that the task could not complete successfully. The error is logged but does
not stop the scheduler.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".