Skip to main content

AsyncJobProvider

Trait AsyncJobProvider 

Source
pub trait AsyncJobProvider {
    // Required methods
    fn create_job(
        &self,
        tenant: &TenantId,
        project: &ProjectId,
        job: CreateAsyncJob,
    ) -> impl Future<Output = Result<AsyncJob, OperationOutcomeError>> + Send;
    fn read_job(
        &self,
        tenant: &TenantId,
        project: &ProjectId,
        id: &str,
    ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send;
    fn count_live_jobs(
        &self,
        tenant: &TenantId,
        project: &ProjectId,
    ) -> impl Future<Output = Result<i64, OperationOutcomeError>> + Send;
    fn cancel_job(
        &self,
        tenant: &TenantId,
        project: &ProjectId,
        id: &str,
    ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send;
    fn claim_job(
        &self,
        kinds: &[&str],
        lease: &JobLease,
    ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send;
    fn renew_lease(
        &self,
        id: &str,
        lease: &JobLease,
        progress: Option<&str>,
    ) -> impl Future<Output = Result<LeaseRenewal, OperationOutcomeError>> + Send;
    fn finish_job(
        &self,
        id: &str,
        worker: &str,
        result: JobResult,
        retention: Duration,
    ) -> impl Future<Output = Result<bool, OperationOutcomeError>> + Send;
    fn fail_abandoned_jobs(
        &self,
        outcome: &Value,
        retention: Duration,
    ) -> impl Future<Output = Result<u64, OperationOutcomeError>> + Send;
    fn delete_expired_jobs(
        &self,
        limit: i64,
    ) -> impl Future<Output = Result<Vec<AsyncJob>, OperationOutcomeError>> + Send;
}

Required Methods§

Source

fn create_job( &self, tenant: &TenantId, project: &ProjectId, job: CreateAsyncJob, ) -> impl Future<Output = Result<AsyncJob, OperationOutcomeError>> + Send

Queues a job. Its id is generated here and is what the status URL carries.

Source

fn read_job( &self, tenant: &TenantId, project: &ProjectId, id: &str, ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send

A job of this project, whatever its state, until it expires.

Source

fn count_live_jobs( &self, tenant: &TenantId, project: &ProjectId, ) -> impl Future<Output = Result<i64, OperationOutcomeError>> + Send

Jobs of this project that are queued or running. Kick-offs cap this.

Source

fn cancel_job( &self, tenant: &TenantId, project: &ProjectId, id: &str, ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send

Cancels a job of this project. A queued job never runs; a running one finds out at its next lease renewal; a finished one gives up its result. Returns the job as it was before, or None if there is no such job or it was already cancelled.

Source

fn claim_job( &self, kinds: &[&str], lease: &JobLease, ) -> impl Future<Output = Result<Option<AsyncJob>, OperationOutcomeError>> + Send

Takes the oldest claimable job of one of kinds for lease.worker: queued, or in progress with a lapsed lease, and with attempts left. Claiming is one statement, so two workers never take the same job.

Source

fn renew_lease( &self, id: &str, lease: &JobLease, progress: Option<&str>, ) -> impl Future<Output = Result<LeaseRenewal, OperationOutcomeError>> + Send

Extends the lease on a job this worker holds and records progress if given. Lost means stop: the job was cancelled or taken over.

Source

fn finish_job( &self, id: &str, worker: &str, result: JobResult, retention: Duration, ) -> impl Future<Output = Result<bool, OperationOutcomeError>> + Send

Records the result of a job this worker holds and releases the lease. Returns false if the job was no longer this worker’s to finish (it was cancelled or taken over meanwhile), in which case the result is dropped.

Source

fn fail_abandoned_jobs( &self, outcome: &Value, retention: Duration, ) -> impl Future<Output = Result<u64, OperationOutcomeError>> + Send

Fails every in-progress job whose lease has lapsed and that has no attempts left, recording outcome on each. Returns how many.

Source

fn delete_expired_jobs( &self, limit: i64, ) -> impl Future<Output = Result<Vec<AsyncJob>, OperationOutcomeError>> + Send

Removes every job past its expires_at, returning them so their handlers can remove what they produced.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§