abstract class Amber::Jobs::QueueAdapter

Overview

Abstract base class for job queue storage adapters.

All queue storage implementations should inherit from this class and implement the required abstract methods. This allows the Amber jobs system to work with any backend storage system (in-memory, Redis, database, etc.) through a unified interface.

Built-in Adapters

Example Custom Adapter

class RedisQueueAdapter < Amber::Jobs::QueueAdapter
  def initialize(@redis : Redis::Client)
  end

  def enqueue(envelope : JobEnvelope)
    @redis.lpush("queue:#{envelope.queue}", envelope.to_json)
  end

  # ... implement other abstract methods
end

Direct Known Subclasses

Defined in:

amber/jobs/queue_adapter.cr

Instance Method Summary

Instance Method Detail

abstract def all_jobs : Array(JobEnvelope) #

Returns all jobs across all queues. Useful for monitoring and inspection.


[View source]
abstract def clear(queue : String) : Nil #

Removes all jobs from the specified queue.


[View source]
def close : Nil #

Called when the adapter is being shut down. Override this method to perform cleanup operations.


[View source]
abstract def dead_jobs : Array(JobEnvelope) #

Returns all jobs that have been marked as dead (exceeded max retries).


[View source]
abstract def dequeue(queue : String) : JobEnvelope | Nil #

Removes and returns the next ready job from the specified queue. Returns nil if the queue is empty or no jobs are ready.


[View source]
abstract def enqueue(envelope : JobEnvelope) : Nil #

Adds a job envelope to the queue for processing.


[View source]
def healthy? : Bool #

Returns true if the adapter is healthy and ready to handle operations. Override this method to implement health checks for your storage backend.


[View source]
abstract def mark_completed(id : String) : Nil #

Marks a job as completed by its ID.


[View source]
abstract def mark_failed(id : String, error : String) : Nil #

Marks a job as failed by its ID, recording the error message.


[View source]
abstract def retry_failed(id : String) : Nil #

Re-enqueues a failed job for retry by its ID.


[View source]
abstract def schedule(envelope : JobEnvelope, at : Time) : Nil #

Schedules a job envelope for execution at a specific time.


[View source]
abstract def size(queue : String) : Int32 #

Returns the number of pending jobs in the specified queue.


[View source]