pub trait BackgroundTask:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &'static str;
fn interval(&self) -> Duration;
fn run<'a>(&'a self, ctx: &'a TaskContext) -> BoxFuture<'a, Result<()>>;
// Provided method
fn http_endpoints(&self) -> Vec<TaskEndpoint> { ... }
}Expand description
A periodic background task registered with the daemon.
The daemon spawns one tokio task per registered plugin at startup and ticks
it at interval(). Each tick counts as activity for the watchdog. Errors
returned from run are logged but don’t kill the daemon.
Tasks can optionally expose HTTP endpoints (e.g. to surface their latest
computed state, or to trigger an on-demand re-run) via Self::http_endpoints.
The daemon mounts each at /tasks/{task-name}/{endpoint-name} and routes
matching requests to the handler.
Required Methods§
fn name(&self) -> &'static str
fn interval(&self) -> Duration
fn run<'a>(&'a self, ctx: &'a TaskContext) -> BoxFuture<'a, Result<()>>
Provided Methods§
Sourcefn http_endpoints(&self) -> Vec<TaskEndpoint>
fn http_endpoints(&self) -> Vec<TaskEndpoint>
Endpoints this task wants the daemon to expose under
/tasks/{self.name()}/{endpoint.name}.
Default is “no endpoints”. Endpoint handlers are ’static closures, so
they should capture an Arc of whatever shared state they need rather
than borrowing from self.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".