Bedrock.JobQueue.Internal (bedrock_job_queue v0.2.0)

View Source

Internal implementation for JobQueue operations.

This module provides the backing implementation for functions defined by use Bedrock.JobQueue. All functions accept a jobqueuemodule as the first argument and use its `__config/0` to get repo, workers, etc.

While technically public, these functions are meant to be called through the generated JobQueue module rather than directly.

Summary

Functions

Initializes the root directory for the JobQueue module.

Returns the root keyspace for the given JobQueue module.

Functions

enqueue(job_queue_module, queue_id, topic, payload, opts)

Enqueues a job for processing.

Options

  • :at - Schedule for a specific DateTime
  • :in - Delay in milliseconds before processing
  • :priority - Integer priority (lower = higher priority, default: 100)
  • :max_retries - Maximum retry attempts (default: 3)
  • :id - Custom job ID (default: auto-generated UUID)

Examples

# Immediate processing
enqueue(MyQueue, "tenant", "topic", payload)

# Schedule for specific time
enqueue(MyQueue, "tenant", "topic", payload, at: ~U[2024-01-15 10:00:00Z])

# Delay by duration
enqueue(MyQueue, "tenant", "topic", payload, in: :timer.hours(1))

# With priority
enqueue(MyQueue, "tenant", "topic", payload, priority: 0)

init_root(repo, job_queue_module)

Initializes the root directory for the JobQueue module.

Creates or opens the directory and caches the resulting keyspace in persistent_term. Must be called within a transaction (or will create one).

Returns {:ok, keyspace} on success.

root_keyspace(job_queue_module)

Returns the root keyspace for the given JobQueue module.

Reads from cache (populated by init_root/2 during startup). Falls back to creating a Keyspace from directory path if not cached.

stats(job_queue_module, queue_id, opts)

Gets queue statistics.