pub struct ServerConfig {Show 20 fields
pub server_name: String,
pub worker_count: usize,
pub polling_interval: Duration,
pub job_timeout: Duration,
pub queues: Vec<String>,
pub auto_start: bool,
pub fetch_batch_size: usize,
pub enable_scheduler: bool,
pub scheduler_poll_interval: Duration,
pub shutdown_timeout: Duration,
pub stale_processing_after: Duration,
pub enable_recurring: bool,
pub recurring_poll_interval: Duration,
pub enable_cleanup: bool,
pub cleanup_interval: Duration,
pub succeeded_ttl: Duration,
pub failed_ttl: Duration,
pub enable_heartbeat: bool,
pub heartbeat_interval: Duration,
pub dead_server_timeout: Duration,
}Expand description
Configuration for the background job server
Fields§
§server_name: StringServer name identifier
worker_count: usizeNumber of worker threads to run
polling_interval: DurationPolling interval for checking new jobs
job_timeout: DurationTimeout for job execution
queues: Vec<String>Queues to process (empty means all queues)
auto_start: boolWhether the server should start automatically
fetch_batch_size: usizeMaximum number of jobs to fetch per polling cycle
enable_scheduler: boolEnable the job scheduler
scheduler_poll_interval: DurationScheduler polling interval
shutdown_timeout: DurationGrace period given to in-flight workers after stop() cancels the
shutdown token. Workers that haven’t completed their current job by
then are aborted and the jobs will need lock-expiry / stale-processing
recovery to be picked up again.
stale_processing_after: DurationA Processing job is treated as stranded (and re-queued on startup)
once its started_at is older than this threshold. Default: 5 minutes.
This should comfortably exceed the typical job_timeout so a worker
that’s still alive isn’t fighting with the recovery sweep.
enable_recurring: boolEnable the recurring-job poller that materializes due
RecurringJob templates.
recurring_poll_interval: DurationPoll interval for the recurring-job poller. Defaults to 5 seconds so minute-granularity crons fire promptly without hammering storage.
enable_cleanup: boolEnable the background cleanup worker that deletes rows whose
expires_at is in the past.
cleanup_interval: DurationInterval between cleanup sweeps. Defaults to 1 minute.
succeeded_ttl: DurationTTL stamped onto successfully-completed jobs. Defaults to 24 hours.
failed_ttl: DurationTTL stamped onto permanently-failed jobs. Defaults to 7 days.
enable_heartbeat: boolEnable the server heartbeat + dead-peer reclaim worker (D1).
When enabled, this server registers itself in the storage-level
server registry, bumps its last_heartbeat on every
heartbeat_interval, and periodically scans for peers whose
heartbeat has gone stale. Dead peers’ in-flight Processing jobs
are actively reclaimed back to Enqueued.
Disabled by default so single-server deployments don’t pay for an unused registry.
heartbeat_interval: DurationHow often to bump this server’s last_heartbeat row. Defaults to
10 seconds.
dead_server_timeout: DurationA peer is treated as dead once its last_heartbeat is older than
this threshold. Defaults to 60 seconds — should comfortably exceed
heartbeat_interval so brief slowdowns don’t trigger reclaim.
Implementations§
Source§impl ServerConfig
impl ServerConfig
Sourcepub fn worker_count(self, count: usize) -> Self
pub fn worker_count(self, count: usize) -> Self
Set the number of workers
Sourcepub fn polling_interval(self, interval: Duration) -> Self
pub fn polling_interval(self, interval: Duration) -> Self
Set the polling interval
Sourcepub fn job_timeout(self, timeout: Duration) -> Self
pub fn job_timeout(self, timeout: Duration) -> Self
Set the job timeout
Sourcepub fn fetch_batch_size(self, size: usize) -> Self
pub fn fetch_batch_size(self, size: usize) -> Self
Set the fetch batch size
Sourcepub fn enable_scheduler(self, enable: bool) -> Self
pub fn enable_scheduler(self, enable: bool) -> Self
Enable or disable the scheduler
Sourcepub fn shutdown_timeout(self, timeout: Duration) -> Self
pub fn shutdown_timeout(self, timeout: Duration) -> Self
Set how long stop() waits for in-flight workers before aborting.
Sourcepub fn stale_processing_after(self, threshold: Duration) -> Self
pub fn stale_processing_after(self, threshold: Duration) -> Self
Set the staleness threshold for re-queuing stranded Processing jobs
on startup.
Sourcepub fn enable_recurring(self, enable: bool) -> Self
pub fn enable_recurring(self, enable: bool) -> Self
Enable or disable the recurring-job poller.
Sourcepub fn recurring_poll_interval(self, interval: Duration) -> Self
pub fn recurring_poll_interval(self, interval: Duration) -> Self
Set the recurring-job poll interval.
Sourcepub fn enable_cleanup(self, enable: bool) -> Self
pub fn enable_cleanup(self, enable: bool) -> Self
Enable or disable the background cleanup worker.
Sourcepub fn cleanup_interval(self, interval: Duration) -> Self
pub fn cleanup_interval(self, interval: Duration) -> Self
Set the cleanup-worker sweep interval.
Sourcepub fn succeeded_ttl(self, ttl: Duration) -> Self
pub fn succeeded_ttl(self, ttl: Duration) -> Self
Set the TTL stamped onto successfully-completed jobs.
Sourcepub fn failed_ttl(self, ttl: Duration) -> Self
pub fn failed_ttl(self, ttl: Duration) -> Self
Set the TTL stamped onto permanently-failed jobs.
Sourcepub fn enable_heartbeat(self, enable: bool) -> Self
pub fn enable_heartbeat(self, enable: bool) -> Self
Enable or disable the heartbeat + dead-peer reclaim worker.
Sourcepub fn heartbeat_interval(self, interval: Duration) -> Self
pub fn heartbeat_interval(self, interval: Duration) -> Self
Set the heartbeat bump interval.
Sourcepub fn dead_server_timeout(self, timeout: Duration) -> Self
pub fn dead_server_timeout(self, timeout: Duration) -> Self
Set the peer-dead staleness threshold.
Trait Implementations§
Source§impl Clone for ServerConfig
impl Clone for ServerConfig
Source§fn clone(&self) -> ServerConfig
fn clone(&self) -> ServerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more