quasar_jobs/store

Store port for durable state. Implementations provide atomic transitions. Resource ownership remains with the application that opened the Store.

Types

pub type Error {
  Unavailable
  Timeout
  NotFound
  InvalidTransition(job.TransitionError)
  StaleExecution
}

Constructors

pub opaque type Store

Values

pub fn cancel(
  store: Store,
  id: job.JobId,
) -> Result(job.Job, Error)
pub fn claim(
  store: Store,
  queue: String,
  limit: Int,
  owner: String,
  now: Int,
  lease_ms: Int,
) -> Result(List(job.Job), Error)

The owner argument is a diagnostic prefix. Each call adds a fresh nonce; adapters must preserve it and atomically match owner AND attempt for every execution mutation. This also fences attempts after a manual retry reset.

pub fn close(store: Store) -> Result(Nil, Error)

Releases only resources created by this adapter. Borrowed resources (such as a Pog pool passed to quasar_postgres.new) are never stopped. Quasar never invokes close: the application calls it after all runtimes and commands using this Store have finished.

pub fn complete(
  store: Store,
  token: job.ExecutionToken,
  now: Int,
) -> Result(job.Job, Error)
pub fn fail(
  store: Store,
  token: job.ExecutionToken,
  error: job.JobError,
  available_at: Int,
) -> Result(job.Job, Error)
pub fn from_operations(
  insert insert: fn(job.NewJob, String, Int, Int) -> Result(
    job.JobId,
    Error,
  ),
  get get: fn(job.JobId) -> Result(job.Job, Error),
  claim claim: fn(String, Int, String, Int, Int) -> Result(
    List(job.Job),
    Error,
  ),
  complete complete: fn(job.ExecutionToken, Int) -> Result(
    job.Job,
    Error,
  ),
  fail fail: fn(job.ExecutionToken, job.JobError, Int) -> Result(
    job.Job,
    Error,
  ),
  cancel cancel: fn(job.JobId) -> Result(job.Job, Error),
  retry retry: fn(job.JobId, Int) -> Result(job.Job, Error),
  renew_lease renew_lease: fn(job.ExecutionToken, Int) -> Result(
    job.Job,
    Error,
  ),
  close close: fn() -> Result(Nil, Error),
) -> Store
pub fn get(store: Store, id: job.JobId) -> Result(job.Job, Error)
pub fn insert(
  store: Store,
  new_job: job.NewJob,
  queue: String,
  available_at: Int,
  now: Int,
) -> Result(job.JobId, Error)
pub fn renew_lease(
  store: Store,
  token: job.ExecutionToken,
  expires_at: Int,
) -> Result(job.Job, Error)
pub fn retry(
  store: Store,
  id: job.JobId,
  now: Int,
) -> Result(job.Job, Error)
Search Document