abstract class
Amber::Jobs::QueueAdapter
- Amber::Jobs::QueueAdapter
- Reference
- Object
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
MemoryQueueAdapter- Thread-safe in-memory queue (default, always available)
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.crInstance Method Summary
-
#all_jobs : Array(JobEnvelope)
Returns all jobs across all queues.
-
#clear(queue : String) : Nil
Removes all jobs from the specified queue.
-
#close : Nil
Called when the adapter is being shut down.
-
#dead_jobs : Array(JobEnvelope)
Returns all jobs that have been marked as dead (exceeded max retries).
-
#dequeue(queue : String) : JobEnvelope | Nil
Removes and returns the next ready job from the specified queue.
-
#enqueue(envelope : JobEnvelope) : Nil
Adds a job envelope to the queue for processing.
-
#healthy? : Bool
Returns true if the adapter is healthy and ready to handle operations.
-
#mark_completed(id : String) : Nil
Marks a job as completed by its ID.
-
#mark_failed(id : String, error : String) : Nil
Marks a job as failed by its ID, recording the error message.
-
#retry_failed(id : String) : Nil
Re-enqueues a failed job for retry by its ID.
-
#schedule(envelope : JobEnvelope, at : Time) : Nil
Schedules a job envelope for execution at a specific time.
-
#size(queue : String) : Int32
Returns the number of pending jobs in the specified queue.
Instance Method Detail
Returns all jobs across all queues. Useful for monitoring and inspection.
Called when the adapter is being shut down. Override this method to perform cleanup operations.
Returns all jobs that have been marked as dead (exceeded max retries).
Removes and returns the next ready job from the specified queue. Returns nil if the queue is empty or no jobs are ready.
Adds a job envelope to the queue for processing.
Returns true if the adapter is healthy and ready to handle operations. Override this method to implement health checks for your storage backend.
Marks a job as failed by its ID, recording the error message.
Re-enqueues a failed job for retry by its ID.
Schedules a job envelope for execution at a specific time.
Returns the number of pending jobs in the specified queue.