pub struct JobProcessor { /* private fields */ }Expand description
Job processor that executes jobs and manages their lifecycle
Implementations§
Source§impl JobProcessor
impl JobProcessor
Sourcepub fn new(
worker_registry: Arc<WorkerRegistry>,
storage: Arc<dyn Storage>,
worker_config: WorkerConfig,
) -> Self
pub fn new( worker_registry: Arc<WorkerRegistry>, storage: Arc<dyn Storage>, worker_config: WorkerConfig, ) -> Self
Create a new job processor
Sourcepub fn with_retry_policy(
worker_registry: Arc<WorkerRegistry>,
storage: Arc<dyn Storage>,
worker_config: WorkerConfig,
retry_policy: RetryPolicy,
) -> Self
pub fn with_retry_policy( worker_registry: Arc<WorkerRegistry>, storage: Arc<dyn Storage>, worker_config: WorkerConfig, retry_policy: RetryPolicy, ) -> Self
Create a new job processor with custom retry policy
Sourcepub fn with_cancellation(self, cancel_token: CancellationToken) -> Self
pub fn with_cancellation(self, cancel_token: CancellationToken) -> Self
Install a cancellation token that will be cloned into every
WorkerContext produced by this processor. Used by
BackgroundJobServer to wire cooperative shutdown through to worker
impls.
Sourcepub fn with_ttls(self, succeeded_ttl: Duration, failed_ttl: Duration) -> Self
pub fn with_ttls(self, succeeded_ttl: Duration, failed_ttl: Duration) -> Self
Override the TTLs stamped onto job.expires_at when jobs reach a
final state. The CleanupWorker uses expires_at to drop rows
out-of-band.
Sourcepub fn with_middleware(self, middleware: Vec<Arc<dyn JobMiddleware>>) -> Self
pub fn with_middleware(self, middleware: Vec<Arc<dyn JobMiddleware>>) -> Self
Replace the middleware stack that wraps worker.execute. The
processor’s built-in TracingMiddleware is dropped when you call
this — pass it in yourself (usually as the first entry) if you
still want structured spans around every job.
Middleware runs in registration order: the first entry is the outermost layer, the last is closest to the worker.
Sourcepub fn with_state_change_hook(self, hook: StateChangeHook) -> Self
pub fn with_state_change_hook(self, hook: StateChangeHook) -> Self
Install an observer fired after every persisted state transition.
See StateChangeHook for semantics.
Sourcepub fn get_worker_id(&self) -> &str
pub fn get_worker_id(&self) -> &str
Get the worker ID for this processor
Sourcepub async fn process_job(&self, job: Job) -> Result<()>
pub async fn process_job(&self, job: Job) -> Result<()>
Process a single job