Forge jobs module — background task queue (PostgreSQL/SQLite backends).
| Tier | application |
| Role | unclassified (baselined) |
| Path | crates/application/jobs |
| Edition | 2024 |
| Targets | application_jobs, pg_forge_jobs |
| Public items | 25 across 4 modules |
| Tests | 2 |
What it is for
application-jobs — background task queue.
B-009: before this, migrations() returned Vec::new() and migrate_pending returned Ok(0), so jobs/job_attempts (plus the fence/lease/backoff/DLQ columns and constraints added by migrations 002-010, crates/infrastructure/jobs/migrations/) were never created by anything that actually called this module's own migration path. Mirrors application-encounters's pattern exactly.
Capabilities
JobsModule
application-jobs — background task queue.
| Item |
|---|
pub struct JobsModule |
JobsModule :: fn new() -> Self |
JobsModule :: fn name(& self) -> & 'static str |
JobsModule :: fn version(& self) -> & 'static str |
JobsModule :: fn migrations(& self) -> Vec <MigrationSet> |
JobsModule :: async fn migrate_pending(& self, pool : & PgPool) -> std::result::Result <u32, MigrationError> |
JobsModule :: fn permission_codes(& self) -> Vec <String> |
api (other)
HTTP API routers for application-jobs.
| Item |
|---|
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, |
api::jobs_admin (other)
Jobs admin REST router.
| Item |
|---|
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, |
CancelQuery
Jobs admin REST router.
| Item |
|---|
pub struct CancelQuery |
CleanupInput
Jobs admin REST router.
| Item |
|---|
pub struct CleanupInput |
CountQuery
Jobs admin REST router.
| Item |
|---|
pub struct CountQuery |
DetailQuery
Jobs admin REST router.
| Item |
|---|
pub struct DetailQuery |
ListQuery
Jobs admin REST router.
| Item |
|---|
pub struct ListQuery |
RetryFailedInput
Jobs admin REST router.
| Item |
|---|
pub struct RetryFailedInput |
services::jobs (other)
Jobs service — thin wrapper around
| Item |
|---|
async fn queue_stats(pool : & PgPool, tenant_id : Uuid) -> Result <QueueStats, JobError> |
async fn export_queue_stats(pool : & PgPool, tenant_id : Uuid, registry : & Registry,) -> Result <QueueStats, JobError> |
async fn list_by_status(pool : & PgPool, tenant_id : Uuid, status : JobStatus,) -> Result <Vec <Job>, JobError> |
async fn get(pool : & PgPool, tenant_id : Uuid, id : Uuid) -> Result <Job, JobError> |
async fn count_by_status(pool : & PgPool, tenant_id : Uuid, status : JobStatus,) -> Result <i64, JobError> |
async fn retry_failed(pool : & PgPool, tenant_id : Uuid, job_type : Option <& str>,) -> Result <u64, JobError> |
async fn cancel(pool : & PgPool, tenant_id : Uuid, id : Uuid) -> Result <(), JobError> |
async fn cleanup(pool : & PgPool, days_old : i32) -> Result <u64, JobError> |
async fn list_attempts(pool : & PgPool, tenant_id : Uuid, job_id : Uuid,) -> Result <Vec <JobAttempt>, JobError> |
async fn latest_attempt(pool : & PgPool, tenant_id : Uuid, job_id : Uuid,) -> Result <Option <JobAttempt>, JobError> |
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
application_jobs
apiapi::jobs_adminservicesservices::jobs
flowchart TD n_application_jobs["application_jobs"] n_application_jobs --> n_api["api"] n_api --> n_api__jobs_admin["jobs_admin"] n_application_jobs --> n_services["services"] n_services --> n_services__jobs["jobs"]
Public surface
`crate root`
| Item | What it is |
|---|---|
pub struct JobsModule | — |
JobsModule :: fn new() -> Self | — |
JobsModule :: fn name(& self) -> & 'static str | — |
JobsModule :: fn version(& self) -> & 'static str | — |
JobsModule :: fn migrations(& self) -> Vec <MigrationSet> | — |
JobsModule :: async fn migrate_pending(& self, pool : & PgPool) -> std::result::Result <u32, MigrationError> | — |
JobsModule :: fn permission_codes(& self) -> Vec <String> | — |
`api`
| Item | What it is |
|---|---|
fn admin_router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, | Admin router for jobs surfaces, generic over the consumer's state S. |
`api::jobs_admin`
| Item | What it is |
|---|---|
pub struct ListQuery | — |
pub struct CountQuery | — |
pub struct DetailQuery | — |
pub struct RetryFailedInput | — |
pub struct CancelQuery | — |
pub struct CleanupInput | — |
fn router <S>() -> Router <S> where S : Clone + Send + Sync + 'static, PgPool : FromRef <S>, | — |
`services::jobs`
| Item | What it is |
|---|---|
async fn queue_stats(pool : & PgPool, tenant_id : Uuid) -> Result <QueueStats, JobError> | US-2.4.9: the tenant's queue-health snapshot — depth by status, oldest ready-pending age, failure counts by class, per-type backlog |
async fn export_queue_stats(pool : & PgPool, tenant_id : Uuid, registry : & Registry,) -> Result <QueueStats, JobError> | US-2.4.9: export the queue-health snapshot into a application-metrics Registry as gauges — one per status / failure-class / job-type, plus the oldest ready-pending age — so queue health is a real metric, not just an ad-hoc REST payload |
async fn list_by_status(pool : & PgPool, tenant_id : Uuid, status : JobStatus,) -> Result <Vec <Job>, JobError> | List jobs for a tenant filtered by status |
async fn get(pool : & PgPool, tenant_id : Uuid, id : Uuid) -> Result <Job, JobError> | Fetch one job scoped to its tenant |
async fn count_by_status(pool : & PgPool, tenant_id : Uuid, status : JobStatus,) -> Result <i64, JobError> | Convenience over list_by_status — count rows in a status for the dashboard widget |
async fn retry_failed(pool : & PgPool, tenant_id : Uuid, job_type : Option <& str>,) -> Result <u64, JobError> | Retry failed jobs for a tenant by resetting their status to pending + clearing attempts / last_error |
async fn cancel(pool : & PgPool, tenant_id : Uuid, id : Uuid) -> Result <(), JobError> | Cancel a pending or running job |
async fn cleanup(pool : & PgPool, days_old : i32) -> Result <u64, JobError> | Cleanup terminal jobs older than days_old |
async fn list_attempts(pool : & PgPool, tenant_id : Uuid, job_id : Uuid,) -> Result <Vec <JobAttempt>, JobError> | List the attempt-log for one job (Sprint 0.2 event log) |
async fn latest_attempt(pool : & PgPool, tenant_id : Uuid, job_id : Uuid,) -> Result <Option <JobAttempt>, JobError> | Most recent attempt for triage ("what class was the last failure?") |
No pub use re-exports: every item above is declared in this crate.
Boundary
Reaches into infrastructure, platform.
Shares tier application with 120 other crates: application-agreements, application-ai, application-analytics, application-approvals, application-assessments, application-audit-log, application-auth, application-billing, … (120 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) | application |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/application/jobs |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_application["application"] --> n_infrastructure["infrastructure"] n_application["application"] --> n_platform["platform"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `application-core` | application | no | always |
| `application-metrics` | application | no | always |
| `infrastructure-jobs` | infrastructure | no | always |
| `platform-dto` | platform | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
axum | ^0.7 | multipart | 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 | no | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
tracing | ^0.1 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development. None.
Build. None.
Depended on by. Nothing in this workspace.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR SELF["application-jobs"] SELF -->|runtime| n_application_core["application-core"] SELF -->|runtime| n_application_metrics["application-metrics"] SELF -->|runtime| n_infrastructure_jobs["infrastructure-jobs"] SELF -->|runtime| n_platform_dto["platform-dto"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | application_jobs | `src/lib.rs` |
| test | pg_forge_jobs | `tests/pg_forge_jobs.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 | yes |
| unsafe code | none detected |
| environment variables | yes |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
| Variable | Read in |
|---|---|
CARGO_PKG_VERSION | src/lib.rs |
Related capabilities
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 1 |
| Integration tests | 1 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 1 | 0 | 0 |
api | 1 | 0 | 0 |
api::jobs_admin | 7 | 0 | 0 |
services::jobs | 10 | 0 | 0 |
What the tests establish, by name:
migrate_pending_creates_jobs_table—tests/pg_forge_jobs.rstest_module_migrations_non_empty—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 11 | 25 |
Public modules with a //! block | 3 | 4 |
pie showData
title Public items with rustdoc
"Documented" : 11
"No rustdoc detected" : 14
Metrics
| Metric | Value |
|---|---|
| Rust source files | 5 |
| Source lines | 569 |
| Code lines | 413 |
| Public API items | 25 |
| Public modules | 4 |
| Tests | 2 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 14 |
| Workspace reverse dependencies | 0 |
pie showData
title Public API by kind
"function" : 12
"method" : 6
"struct" : 7
pie showData
title Rust source composition
"Code" : 413
"Blank or comment" : 156
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.