bg_jobs/queue

Types

pub type Message {
  Shutdown
  StartPolling
  StopPolling
  WaitBetweenPoll
  HandleError(jobs.Job, exception: String)
  HandleSuccess(jobs.Job)
  ProcessJobs
}

Constructors

  • Shutdown
  • StartPolling
  • StopPolling
  • WaitBetweenPoll
  • HandleError(jobs.Job, exception: String)
  • HandleSuccess(jobs.Job)
  • ProcessJobs

Represents a queue that should be created

pub type Spec {
  Spec(
    name: String,
    workers: List(jobs.Worker),
    max_retries: Int,
    init_timeout: Int,
    max_concurrent_jobs: Int,
    poll_interval: Int,
    event_listeners: List(events.EventListener),
  )
}

Constructors

  • Spec(
      name: String,
      workers: List(jobs.Worker),
      max_retries: Int,
      init_timeout: Int,
      max_concurrent_jobs: Int,
      poll_interval: Int,
      event_listeners: List(events.EventListener),
    )

Functions

pub fn new(name: String) -> Spec

Start building a new queue-spec

NOTE: Name needs to be the same on restarts, but unique across all queues, even if running on different machines

pub fn with_event_listener(
  spec: Spec,
  event_listener: fn(Event) -> Nil,
) -> Spec

Add a event listener to the list of event listners for the queue

pub fn with_event_listeners(
  spec: Spec,
  event_listeners: List(fn(Event) -> Nil),
) -> Spec

Append a list of event listeners for the queue

pub fn with_init_timeout(spec: Spec, init_timeout: Int) -> Spec

Amount of time in milliseconds the queue is given to start

pub fn with_max_concurrent_jobs(
  spec: Spec,
  max_concurrent_jobs: Int,
) -> Spec

Maximum number of jobs to run in parallel

pub fn with_max_retries(spec: Spec, max_retries: Int) -> Spec

Maximum times a job will be retried before being considered failed and moved to the failed_jobs table

pub fn with_name(spec: Spec, name: String) -> Spec

Set the name of the queue

NOTE: This needs to be the same on restarts, but unique across all queues, even if running on different machines

pub fn with_poll_interval_ms(
  spec: Spec,
  poll_interval: Int,
) -> Spec

Time in milli seconds to wait in between checking for new jobs

pub fn with_worker(spec: Spec, worker: Worker) -> Spec

Add a worker the queue will poll for and run

pub fn with_workers(spec: Spec, workers: List(Worker)) -> Spec

Add multiple workers the queue will poll for and run

Search Document