Skip to main content

JobRepository

Struct JobRepository 

Source
pub struct JobRepository { /* private fields */ }

Implementations§

Source§

impl JobRepository

Source

pub fn new(pool: PgPool) -> Self

Source

pub fn pool(&self) -> &PgPool

Source

pub async fn enqueue( &self, input: NewJob, ) -> Result<EnqueueOutcome, DomainError>

Insert a job. When an idempotency_key is set and a non-terminal (or succeeded) row already exists for (kind, key), returns the existing row rather than inserting a duplicate.

Source

pub async fn append_log( &self, job_id: JobId, attempt_no: Option<i32>, level: &str, message: &str, fields: Value, ) -> Result<JobLogRecord, DomainError>

Source

pub async fn list_logs( &self, id: JobId, after_id: Option<i64>, limit: u32, ) -> Result<Vec<JobLogRecord>, DomainError>

Source

pub async fn dequeue( &self, queues: &[String], worker_id: &str, lease: Duration, ) -> Result<Option<SbolJob>, DomainError>

Dequeue one job from the given queues, taking a lease for the worker. Uses FOR UPDATE SKIP LOCKED so concurrent workers across the cluster never contend on the same row.

Source

pub async fn renew_lease( &self, job_id: JobId, worker_id: &str, lease: Duration, ) -> Result<bool, DomainError>

Extend the lease on a running job. Returns false when the lease has already been stolen (different leased_by) or the job has transitioned out of running.

Source

pub async fn mark_succeeded( &self, job_id: JobId, worker_id: &str, result: Option<Value>, ) -> Result<(), DomainError>

Source

pub async fn mark_failed( &self, job_id: JobId, worker_id: &str, error: &str, ) -> Result<JobStatus, DomainError>

Mark a failed attempt. If the job still has retries left, transition it back to queued with exponential backoff (60s * 2^attempts, capped at 1 hour). Otherwise it lands in dead.

Source

pub async fn reap_expired_leases(&self) -> Result<u64, DomainError>

Re-queue jobs whose lease has expired. Workers run this on a slow timer; one losing the race is harmless — UPDATE ... WHERE status = 'running' is idempotent under concurrent reapers.

Source

pub async fn get(&self, id: JobId) -> Result<Option<SbolJob>, DomainError>

Source

pub async fn list_attempts( &self, id: JobId, ) -> Result<Vec<JobAttempt>, DomainError>

Per-attempt audit log for a job, newest first. Returns an empty vector when the job exists but has not been dequeued yet, and also when the job id does not exist — callers that care about existence should pair this with Self::get.

Source

pub async fn list( &self, filter: &ListJobsFilter, ) -> Result<Vec<SbolJob>, DomainError>

Source

pub async fn cancel(&self, id: JobId) -> Result<bool, DomainError>

Cancel a job. Only queued jobs cancel cleanly; running jobs are marked cancelled but the worker still finishes its current step (cooperative cancellation is a v2 concern).

Source

pub async fn current_status( &self, id: JobId, ) -> Result<Option<JobStatus>, DomainError>

Used by handler dispatch and the worker’s heartbeat: peek the status without taking a lease.

Source

pub async fn queue_depth_snapshot( &self, ) -> Result<Vec<QueueDepthRow>, DomainError>

Aggregate row count grouped by (status, queue) for the non-terminal lifecycle states. Drives the /metrics sbol_db_jobs_queue_depth gauge. Cheap given the partial dequeue index covers status = 'queued'.

Source

pub async fn oldest_queued_age( &self, ) -> Result<Vec<OldestQueuedAge>, DomainError>

Oldest available_at per queue among queued rows whose available_at <= now(). Lets ops alert on stalled queues without chasing individual job ids.

Source

pub async fn recent_failure_count( &self, within_hours: i64, ) -> Result<i64, DomainError>

Trait Implementations§

Source§

impl Clone for JobRepository

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl JobQueue for JobRepository

Source§

fn enqueue<'life0, 'async_trait>( &'life0 self, input: NewJob, ) -> Pin<Box<dyn Future<Output = Result<EnqueueOutcome, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn append_log<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, job_id: JobId, attempt_no: Option<i32>, level: &'life1 str, message: &'life2 str, fields: Value, ) -> Pin<Box<dyn Future<Output = Result<JobLogRecord, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn list_logs<'life0, 'async_trait>( &'life0 self, id: JobId, after_id: Option<i64>, limit: u32, ) -> Pin<Box<dyn Future<Output = Result<Vec<JobLogRecord>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn dequeue<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, queues: &'life1 [String], worker_id: &'life2 str, lease: Duration, ) -> Pin<Box<dyn Future<Output = Result<Option<SbolJob>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn renew_lease<'life0, 'life1, 'async_trait>( &'life0 self, job_id: JobId, worker_id: &'life1 str, lease: Duration, ) -> Pin<Box<dyn Future<Output = Result<bool, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn mark_succeeded<'life0, 'life1, 'async_trait>( &'life0 self, job_id: JobId, worker_id: &'life1 str, result: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<(), DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn mark_failed<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, job_id: JobId, worker_id: &'life1 str, error: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<JobStatus, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source§

fn reap_expired_leases<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn get<'life0, 'async_trait>( &'life0 self, id: JobId, ) -> Pin<Box<dyn Future<Output = Result<Option<SbolJob>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn list_attempts<'life0, 'async_trait>( &'life0 self, id: JobId, ) -> Pin<Box<dyn Future<Output = Result<Vec<JobAttempt>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn list<'life0, 'life1, 'async_trait>( &'life0 self, filter: &'life1 ListJobsFilter, ) -> Pin<Box<dyn Future<Output = Result<Vec<SbolJob>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn cancel<'life0, 'async_trait>( &'life0 self, id: JobId, ) -> Pin<Box<dyn Future<Output = Result<bool, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn current_status<'life0, 'async_trait>( &'life0 self, id: JobId, ) -> Pin<Box<dyn Future<Output = Result<Option<JobStatus>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn queue_depth_snapshot<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<QueueDepthRow>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn oldest_queued_age<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<OldestQueuedAge>, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn recent_failure_count<'life0, 'async_trait>( &'life0 self, within_hours: i64, ) -> Pin<Box<dyn Future<Output = Result<i64, DomainError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Count jobs that reached a terminal failure (failed or dead) in the last within_hours. Backed by Self::list so every backend reports the same number without backend-specific SQL; the dashboard’s failures tile reads it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more