Expand description
Typed background jobs for Rust services.
worklane is the public-facing facade. Enqueue typed jobs with a Client
and run handlers with a Worker over any Broker (for example the
in-memory broker in the worklane-memory crate).
Application code should usually depend on this crate plus one broker crate.
Lower-level crates such as worklane-core are for broker implementations and
optional integrations.
Core loop: typed payload -> envelope -> broker reserve -> dispatch by kind -> run handler -> ack / retry / fail / dead-letter.
Delivery is at-least-once: a job may run more than once (e.g. after a lease expiry or crash), so handlers must be idempotent.
Structs§
- Building
- Configuration phase: handlers and options can be set. Reached by
Worker::new; left byWorker::build. - Cancellation
- A cooperative cancellation flag for a running job.
- Circuit
Breaker - Per-kind circuit-breaker state, shared across a worker’s in-flight tasks.
- Circuit
Breaker Policy - Tuning for a
CircuitBreaker. - Claim
Check - Offloads oversized payloads to a
PayloadStoreand resolves the references back, implementing the Claim Check pattern. - Client
- Enqueues typed jobs onto a broker.
- Dead
Letter - A job that exhausted its attempts (or failed unrecoverably), retained for inspection along with the last error message.
- FanIn
Policy - Tuning for a fan-in watcher’s poll loop, passed to
Client::fan_in_with_policy. - FanIn
Results - The payload delivered to a fan-in callback: the caller’s
contextplus each dependency’s opaque output bytes, in dependency order. - File
Payload Store - A filesystem-backed
PayloadStore— the reference implementation. - JobAttempt
Event - The observer SPI, defined in
worklane-coreso telemetry integrations can depend on the contract without the facade. Re-exported here as the worker is what invokes it. A per-attempt in-flight event handed to aJobObserver. - JobBuilder
- A builder for configuring and enqueuing a job with custom properties.
- JobContext
- Per-run context handed to a job handler.
- JobEnvelope
- The broker’s view of an enqueued job. The payload is opaque: the broker never inspects or deserializes it.
- JobEvent
- The observer SPI, defined in
worklane-coreso telemetry integrations can depend on the contract without the facade. Re-exported here as the worker is what invokes it. A finished-job event handed to aJobObserver. - JobId
- A unique identifier for an enqueued job.
- JobId
Parse Error - The error returned when
JobIdfails to parse from a string. - Lane
- A validated lane identifier.
- NewJob
- A job to be enqueued: the lane it targets, its kind, an already-serialized payload, how many attempts it may take before being dead-lettered, and an optional delay before it becomes visible for reservation.
- Next
- The continuation handed to a
Middleware: the remaining middleware chain, terminating at the job’s handler. Callrunto proceed. - Ready
- Execution phase: configuration is frozen and the worker can
run. Reached only viaWorker::build. - Reservation
- A reserved job and the receipt required to resolve it.
- Reservation
Receipt - An opaque token proving authority to resolve a specific reservation.
- Retry
Policy - Computes the delay before a failed job is retried, using capped exponential
backoff:
delay = min(base * factor^attempts, cap). - System
Clock - A real clock backed by
Instant. - Wall
Clock - A wall-clock time source anchored at the Unix epoch, guarded to be monotonic non-decreasing for the lifetime of the instance.
- Worker
- Runs registered job handlers, processing up to a configured concurrency of jobs at a time (default 1, i.e. strictly sequential).
Enums§
- Error
- Errors produced by worklane operations.
- JobOutcome
- The observer SPI, defined in
worklane-coreso telemetry integrations can depend on the contract without the facade. Re-exported here as the worker is what invokes it. What ultimately happened to a job, reported to aJobObserver. - JobState
- The state of a job returned by
Broker::classify. - Lane
Error - The reason a lane name failed validation.
Constants§
- DEFAULT_
LANE - The name of the default lane.
- DEFAULT_
MAX_ ATTEMPTS - The default
max_attemptsapplied to enqueued jobs. Re-exported fromworklane-coresoworklane::DEFAULT_MAX_ATTEMPTSis stable. The defaultmax_attemptsapplied to enqueued jobs when a caller does not specify one. Brokers impose no retry policy themselves; this is the default the client- and scheduler-side enqueue paths apply. - DEFAULT_
OFFLOAD_ THRESHOLD - The default offload threshold: payloads larger than this are stored externally. 64 KiB comfortably inlines ordinary jobs while offloading genuinely large ones.
- DEFAULT_
POLL_ INTERVAL - The default idle poll interval for
Worker::run.
Traits§
- Batch
Enqueue - Atomic batch enqueue — an optional
Brokercapability. - Broker
- A backend-agnostic job store and lifecycle primitive.
- Clock
- A monotonic time source, abstracted so brokers derive time-based decisions (visibility, lease expiry, retry scheduling) from an injectable clock rather than reading wall-clock time directly.
- Dead
Letter Store - Dead-letter inspection and maintenance — an optional
Brokercapability. - Job
- A typed background job.
- JobObserver
- The observer SPI, defined in
worklane-coreso telemetry integrations can depend on the contract without the facade. Re-exported here as the worker is what invokes it. Observes the outcome of every job aWorkerresolves. - Middleware
- A handler-dispatch interceptor. See
Worker::with_middlewarefor registration and ordering. - Payload
Store - An external store for oversized job payloads (the Claim Check pattern).
- Queue
Stats - Queue-depth statistics — an optional
Brokercapability. - Result
Store - A pluggable backend for storing opaque job results.
- Scheduled
Store - Optional schedule-claim store used by recurring schedulers.
- Worker
State - Marks a
Worker’s lifecycle phase (typestate). Sealed: the only states areBuildingandReady. - Workflow
- The Workflow extension trait. Provides building blocks for fan-in/fan-out topologies (sequences and fan-ins) built entirely in user-space over the core primitives.
Functions§
- from_
payload - Deserialize a typed payload from bytes (JSON), mapping failures to
Error::Serialization. - to_
payload - Serialize a typed payload to bytes (JSON), mapping failures to
Error::Serialization.
Type Aliases§
- Handler
Error - A boxed error returned by a job handler.
- Handler
Result - The result of running a job handler.
- Result
- A
Resultspecialized to the worklaneErrortype.
Attribute Macros§
- async_
trait - Re-exported so handlers can annotate their
Jobimpl with#[worklane::async_trait].