Skip to main content

ServerConfig

Struct ServerConfig 

Source
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: String

Server name identifier

§worker_count: usize

Number of worker threads to run

§polling_interval: Duration

Polling interval for checking new jobs

§job_timeout: Duration

Timeout for job execution

§queues: Vec<String>

Queues to process (empty means all queues)

§auto_start: bool

Whether the server should start automatically

§fetch_batch_size: usize

Maximum number of jobs to fetch per polling cycle

§enable_scheduler: bool

Enable the job scheduler

§scheduler_poll_interval: Duration

Scheduler polling interval

§shutdown_timeout: Duration

Grace 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: Duration

A 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: bool

Enable the recurring-job poller that materializes due RecurringJob templates.

§recurring_poll_interval: Duration

Poll interval for the recurring-job poller. Defaults to 5 seconds so minute-granularity crons fire promptly without hammering storage.

§enable_cleanup: bool

Enable the background cleanup worker that deletes rows whose expires_at is in the past.

§cleanup_interval: Duration

Interval between cleanup sweeps. Defaults to 1 minute.

§succeeded_ttl: Duration

TTL stamped onto successfully-completed jobs. Defaults to 24 hours.

§failed_ttl: Duration

TTL stamped onto permanently-failed jobs. Defaults to 7 days.

§enable_heartbeat: bool

Enable 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: Duration

How often to bump this server’s last_heartbeat row. Defaults to 10 seconds.

§dead_server_timeout: Duration

A 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

Source

pub fn new(server_name: impl Into<String>) -> Self

Create a new server configuration

Source

pub fn worker_count(self, count: usize) -> Self

Set the number of workers

Source

pub fn polling_interval(self, interval: Duration) -> Self

Set the polling interval

Source

pub fn job_timeout(self, timeout: Duration) -> Self

Set the job timeout

Source

pub fn queues(self, queues: Vec<String>) -> Self

Set the queues to process

Source

pub fn fetch_batch_size(self, size: usize) -> Self

Set the fetch batch size

Source

pub fn enable_scheduler(self, enable: bool) -> Self

Enable or disable the scheduler

Source

pub fn shutdown_timeout(self, timeout: Duration) -> Self

Set how long stop() waits for in-flight workers before aborting.

Source

pub fn stale_processing_after(self, threshold: Duration) -> Self

Set the staleness threshold for re-queuing stranded Processing jobs on startup.

Source

pub fn enable_recurring(self, enable: bool) -> Self

Enable or disable the recurring-job poller.

Source

pub fn recurring_poll_interval(self, interval: Duration) -> Self

Set the recurring-job poll interval.

Source

pub fn enable_cleanup(self, enable: bool) -> Self

Enable or disable the background cleanup worker.

Source

pub fn cleanup_interval(self, interval: Duration) -> Self

Set the cleanup-worker sweep interval.

Source

pub fn succeeded_ttl(self, ttl: Duration) -> Self

Set the TTL stamped onto successfully-completed jobs.

Source

pub fn failed_ttl(self, ttl: Duration) -> Self

Set the TTL stamped onto permanently-failed jobs.

Source

pub fn enable_heartbeat(self, enable: bool) -> Self

Enable or disable the heartbeat + dead-peer reclaim worker.

Source

pub fn heartbeat_interval(self, interval: Duration) -> Self

Set the heartbeat bump interval.

Source

pub fn dead_server_timeout(self, timeout: Duration) -> Self

Set the peer-dead staleness threshold.

Trait Implementations§

Source§

impl Clone for ServerConfig

Source§

fn clone(&self) -> ServerConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ServerConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ServerConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,