Background task queue on PostgreSQL (SKIP LOCKED); Postgres-only per ADR 0022
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/jobs |
| Edition | 2021 |
| Targets | infrastructure_jobs, cancellation, failure, fence, lanes, lanes_pg, pg_job_attempts, reattach, resource_lease, schedule, stats, worker_runtime |
| Public items | 2 across 0 modules |
| Tests | 97 |
What it is for
Background task queue with pluggable backends.
PostgreSQL-only (ADR 0022 — the SQLite backend was removed): SKIP LOCKED provides reliable, distributed job processing.
# Features
postgres(default):PostgreSQLbackend via sqlx
# Example
use infrastructure_jobs::{Job, JobQueue, JobStore};
let store = JobQueue::new(pool);
let job = store.enqueue(tenant_id, "send_email", &payload).await?;
Capabilities
crate root
Background task queue with pluggable backends.
| Item |
|---|
pub const JOBS_SCHEMA_VERSION: u32 |
async fn ensure_schema(pool : & sqlx::PgPool) -> Result <(), sqlx::Error> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub const JOBS_SCHEMA_VERSION: u32 | Schema version this code expects |
async fn ensure_schema(pool : & sqlx::PgPool) -> Result <(), sqlx::Error> | Apply ALL of the jobs crate's migrations to pool (creates/updates jobs, job_attempts, resource-lease, backoff/DLQ, fence/lease, etc.) |
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
JobError | error::JobError |
JobQueue | queue::JobQueue |
JobStore | store::JobStore |
{AttemptOutcomeInput,JobAttempt,JobAttemptStatus} | attempt::{AttemptOutcomeInput,JobAttempt,JobAttemptStatus} |
{ClaimedJob,JobFence} | fence::{ClaimedJob,JobFence} |
{FailureClass,Job,JobPayload,JobStatus,Schedule} | job::{FailureClass,Job,JobPayload,JobStatus,Schedule} |
{LaneConfig,TenantLaneError,TenantLaneSupervisor} | lanes::{LaneConfig,TenantLaneError,TenantLaneSupervisor} |
{LeaseOutcome,RecoveryPolicy,ResourceLease} | resource::{LeaseOutcome,RecoveryPolicy,ResourceLease} |
{ObserveOutcome,ReattachResult,ShutdownHandle,WakeHandle,WakeMode,Worker,WorkerConfig,} | worker::{ObserveOutcome,ReattachResult,ShutdownHandle,WakeHandle,WakeMode,Worker,WorkerConfig,} |
{QueueStats,StatCount} | stats::{QueueStats,StatCount} |
Boundary
Reaches into foundation.
Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | infrastructure |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/infrastructure/jobs |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_infrastructure["infrastructure"] --> n_foundation["foundation"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | yes | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
tokio-util | ^0.7 | — | no | always |
tracing | ^0.1 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. 5 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_cms["application-cms"] -->|uses| SELF n_application_jobs["application-jobs"] -->|uses| SELF n_application_tickets["application-tickets"] -->|uses| SELF n_infrastructure_cron["infrastructure-cron"] -->|uses| SELF n_platform_privacy_scan_api["platform-privacy-scan-api"] -->|uses| SELF SELF["infrastructure-jobs"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
| Feature | Enables | On by default |
|---|---|---|
default | postgres | yes |
postgres | dep:sqlx | yes |
flowchart LR n_default["default"] --> n_postgres["postgres"] n_postgres["postgres"] --> n_dep_sqlx["dep:sqlx"]
Targets
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_jobs | `src/lib.rs` |
| test | cancellation | `tests/cancellation.rs` |
| test | failure | `tests/failure.rs` |
| test | fence | `tests/fence.rs` |
| test | lanes | `tests/lanes.rs` |
| test | lanes_pg | `tests/lanes_pg.rs` |
| test | pg_job_attempts | `tests/pg_job_attempts.rs` |
| test | reattach | `tests/reattach.rs` |
| test | resource_lease | `tests/resource_lease.rs` |
| test | schedule | `tests/schedule.rs` |
| test | stats | `tests/stats.rs` |
| test | worker_runtime | `tests/worker_runtime.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | yes |
| database access | yes |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
5 workspace crates depend on this one: application-cms, application-jobs, application-tickets, infrastructure-cron, platform-privacy-scan-api.
Verification
| Kind | Count |
|---|---|
| Unit tests | 32 |
| Integration tests | 65 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 2 | 0 | 0 |
What the tests establish, by name:
test_a_cancelled_job_is_cancelled_not_failed_or_succeeded—tests/cancellation.rstest_a_handler_that_ignores_the_token_and_succeeds_records_succeeded—tests/cancellation.rstest_cancel_is_fence_scoped—tests/cancellation.rstest_request_cancel_records_intent_without_terminating—tests/cancellation.rstest_the_worker_delivers_a_token_and_records_cancelled—tests/cancellation.rstest_a_retryable_failure_backs_off_before_reclaim—tests/failure.rstest_dead_letter_list_then_replay_preserves_history—tests/failure.rstest_exhausting_attempts_dead_letters_as_attempts_exhausted—tests/failure.rstest_permanent_failure_quarantines_without_consuming_the_budget—tests/failure.rstest_worker_quarantines_on_permanent_handler_error—tests/failure.rstest_a_lost_cas_is_an_error_not_a_silent_noop—tests/fence.rstest_a_reaped_worker_cannot_complete_the_job_that_replaced_it—tests/fence.rstest_a_tenant_cannot_touch_another_tenants_job—tests/fence.rstest_an_attempt_row_exists_before_the_handler_is_invoked—tests/fence.rstest_every_transition_rejects_a_stale_fence—tests/fence.rstest_fence_loss_preserves_the_attempt_as_outcome_unknown—tests/fence.rstest_heartbeat_does_not_advance_the_fence—tests/fence.rstest_irreversible_work_is_not_auto_reclaimed_by_default—tests/fence.rstest_one_pending_job_is_claimed_exactly_once—tests/fence.rstest_admission_is_bounded—tests/lanes.rstest_evict_idle_removes_only_lanes_past_their_window—tests/lanes.rstest_jobs_op_guard_releases_permits_after_the_op—tests/lanes.rstest_per_lane_execution_semaphores_are_separate—tests/lanes.rstest_per_lane_jobs_op_semaphores_are_separate—tests/lanes.rstest_removing_an_idle_tenant_stops_its_poller—tests/lanes.rstest_two_tier_ordering_bounds_a_single_tenant—tests/lanes.rstest_a_lane_claims_only_its_own_tenants_jobs—tests/lanes_pg.rstest_a_lane_reaps_its_tenants_orphaned_jobs—tests/lanes_pg.rstest_execution_semaphore_bounds_handler_concurrency—tests/lanes_pg.rspg_complete_attempt_computes_duration_and_terminal_state—tests/pg_job_attempts.rs- _… 67 more_
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 2 | 2 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 2
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 11 |
| Source lines | 4713 |
| Code lines | 3074 |
| Public API items | 2 |
| Public modules | 0 |
| Tests | 97 |
| Examples | 0 |
| Cargo features | 2 |
| Direct runtime dependencies | 11 |
| Workspace reverse dependencies | 5 |
pie showData
title Public API by kind
"constant" : 1
"function" : 1
pie showData
title Rust source composition
"Code" : 3074
"Blank or comment" : 1639
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.