docs.rs failed to build simple-queue-0.1.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
simple-queue-0.2.2
This crate provides a persisted job queue backed by PostgreSQL with a simple to use interface. Its written as an easy to use async job queue library without macros or generics shenanigans.
Usage boils down to 3 points:
- Implement
Handlertrait - Initialize the queue with a
PgPooland start it - Insert jobs
Default configurations for jobs and queues are.. defaults, so make sure to read through appropriate Job and SimpleQueue documentation.
Features
- Simple handler interface
- Job scheduling and rescheduling
- Job retry support
- Job crash handling
- Job cancellation
- Job fingerprinting (soft identifier)
- Existing jobs deduplication (unique key with noop on job reinsert - only for live jobs)
- Configurable global and per-queue backoff strategy (linear and exponential provided, custom supported)
- 3 tiered job permits (global permit, per queue permit, handler owned limit)
- Stalled job recovery (heartbeat)
- Archive and DLQ (requires
janitorfeature) - Poison job detection (
reaper)
Usage
Handler Implementation
// handlers.rs
use *;
;
Queue Initialization
// main.rs
use *;
async
Thread Structure
┌─────────────┐
│ Entry Point │
└──────┬──────┘
│ spawns
┌─────────────────────┼──────────────────────┐
▼ ▼ ▼
┌────────────────┐ ┌────────────────┐ ┌────────────────┐
│Queue Processor │ │ Janitor │ │ Reaper │
│ / Poller │ └────────────────┘ └────────────────┘
└───────┬────────┘
│
│ wait global permit
▼
┌─────────┐
│ run() │
└────┬────┘
│ job obtained
│
├──────────────────────┐
│ │ spawn first
│ ▼
│ ┌───────────────┐
│ │ Heartbeat │
│ │ Thread │
│ └───────┬───────┘
│ │ ownership
▼ │
wait queue permit │
│ │
▼ │
┌──────────────────────┐ │
│ Job Thread │◄───┘ heartbeat passed in
│ │ (drop job == drop heartbeat)
│ wait handler permit │
│ │ │
│ ▼ │
│ ┌─────────────┐ │
│ │ Process │ │
│ │ Job │ │
│ └─────────────┘ │
└──────────────────────┘
Future Work
- Distributed Semaphores using PostgreSQL
- Temporary store on connection loss
- Job templates
- Queue interactor interface
- PG Listener (to decrease job-to-queue latency)
- Job Queue partitioning (dead tuples accumulation prevention)
Decisions
- JSON for job data for inspectability of DLQ/Archive
- Poll mechanism / non-distributed semaphores as a good enough (for now)