application tier

application-jobs

Forge jobs module — background task queue (PostgreSQL/SQLite backends).

Forge jobs module — background task queue (PostgreSQL/SQLite backends).

Tierapplication
Roleunclassified (baselined)
Pathcrates/application/jobs
Edition2024
Targetsapplication_jobs, pg_forge_jobs
Public items25 across 4 modules
Tests2

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

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`

ItemWhat 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`

ItemWhat 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`

ItemWhat 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`

ItemWhat 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)
Locationcrates/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.

CrateTierOptionalOnly on
`application-core`applicationnoalways
`application-metrics`applicationnoalways
`infrastructure-jobs`infrastructurenoalways
`platform-dto`platformnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
axum^0.7multipartnoalways
chrono^0.4serdenoalways
serde^1derivenoalways
serde_json^1noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
tokio^1fullnoalways
tracing^0.1noalways
uuid^1v4, v7, serde, jsnoalways

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

KindNameSource
libapplication_jobs`src/lib.rs`
testpg_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

PropertyEvidence
async public surfaceyes
async runtimeyes
database accessyes
network I/Oyes
unsafe codenone detected
environment variablesyes

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

VariableRead in
CARGO_PKG_VERSIONsrc/lib.rs

No workspace crate depends on this one.

Verification

KindCount
Unit tests1
Integration tests1
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root100
api100
api::jobs_admin700
services::jobs1000

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc1125
Public modules with a //! block34
pie showData
    title Public items with rustdoc
    "Documented" : 11
    "No rustdoc detected" : 14

Metrics

MetricValue
Rust source files5
Source lines569
Code lines413
Public API items25
Public modules4
Tests2
Examples0
Cargo features0
Direct runtime dependencies14
Workspace reverse dependencies0
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.

All application · Manual