pub trait BackgroundJobProvider: Send + Sync {
// Required methods
fn definition(&self) -> &JobDefinition;
fn execute(&self, ctx: JobContext<'_>) -> Result<JobOutcome, FnError>;
}Expand description
A background-job provider.
Required Methods§
Sourcefn definition(&self) -> &JobDefinition
fn definition(&self) -> &JobDefinition
Static definition (schedule, concurrency, timeout, docs).
Sourcefn execute(&self, ctx: JobContext<'_>) -> Result<JobOutcome, FnError>
fn execute(&self, ctx: JobContext<'_>) -> Result<JobOutcome, FnError>
Execute one run of the job.
§Threading policy
- Driven from Tokio via
tokio::task::spawn_blocking. The host scheduler runs this synchronous method on a blocking worker thread so it never stalls the async runtime. - Must not block the runtime directly. If the job needs to
perform I/O, it must do so on the current (blocking) thread —
never call
block_onagainst the host runtime from insideexecute. - Must observe
JobContext::cancelcooperatively. PollCancellationToken::is_cancelledat every safe point (between batches, before long compute, before issuing each query). The scheduler trips the token on shutdown / reload / explicit cancel; an unresponsive job stays alive until the process exits. - Errors propagate as
FnError. Panics are caught at the scheduler boundary and recorded as a failed run; they do not crash the host.
See docs/PLUGIN_THREADING.md for the long-form rationale.
§Errors
Returns FnError on execution failure. The host’s scheduler
honors the JobDefinition::retry policy.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".