Bedrock.JobQueue.Config (bedrock_job_queue v0.2.0)

View Source

Configuration and defaults for the job queue system.

This module provides configuration struct and utility functions used by the job queue consumer components. The main entry point for configuration is through use Bedrock.JobQueue in your application's JobQueue module.

Fields

  • :repo - The Bedrock Repo module for database operations
  • :concurrency - Maximum concurrent job workers (default: System.schedulers_online())
  • :batch_size - Number of items to dequeue per batch (default: 10)

Backoff

The default_backoff/1 function provides exponential backoff with jitter for failed job retries. Custom backoff functions can be passed via :backoff_fn when starting the consumer.

Summary

Functions

Default exponential backoff function.

Creates a new configuration from options.

Types

t()

@type t() :: %Bedrock.JobQueue.Config{
  batch_size: pos_integer(),
  concurrency: pos_integer(),
  repo: module()
}

Functions

default_backoff(attempt)

@spec default_backoff(non_neg_integer()) :: non_neg_integer()

Default exponential backoff function.

Returns milliseconds to wait before retry based on attempt number (0-indexed).

Formula

delay = 2^attempt * 1000 + random(0..500)

This produces delays of approximately: 1s, 2s, 4s, 8s, 16s, 32s, etc. with up to 500ms of random jitter to prevent thundering herd.

Examples

iex> delay = Config.default_backoff(0)
iex> delay >= 1000 and delay <= 1500
true

iex> delay = Config.default_backoff(3)
iex> delay >= 8000 and delay <= 8500
true

new(opts)

@spec new(keyword()) :: t()

Creates a new configuration from options.

Options

  • :repo - Required. The Bedrock Repo module
  • :concurrency - Max concurrent workers (default: System.schedulers_online())
  • :batch_size - Items per dequeue batch (default: 10)