Queue class

High-level facade for the queue system.

Queue provides a clean API for dispatching jobs, managing workers, monitoring metrics, and inspecting the dead letter queue.

final queue = Queue(driver: MemoryQueueDriver());
queue.dispatch(SendEmailJob('[email protected]', 'Hello!'));
queue.work(concurrency: 4, maxJobsPerSecond: 10);

Constructors

Queue({required QueueDriver driver})
Creates a new Queue instance with the given driver.

Properties

driver QueueDriver
The storage backend for the queue.
final
hashCode int
The hash code for this object.
no setterinherited
isProcessing bool
Returns true if a worker is currently running.
no setter
metrics QueueMetrics
Metrics collector tracking throughput, failures, and processing times.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stats Map<String, dynamic>
Returns a snapshot of current metrics (throughput, failures, timing, etc).
no setter

Methods

clear([String queue = 'default']) Future<void>
Clears all jobs from the specified queue.
clearDeadLetters() Future<void>
Clears the dead letter queue.
deadLetters() Future<List<Map<String, dynamic>>>
Returns all permanently failed jobs from the dead letter queue.
dispatch(Job job) Future<String>
Dispatches a job to its designated queue for background processing.
dispatchAfter(Duration delay, Job job) Future<String>
Dispatches a job with a delay before it becomes available.
dispatchSync(Job job) Future<void>
Dispatches a job and processes it synchronously (blocks until done).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pending([List<String> queues = const ['default']]) Future<Map<String, int>>
Returns the number of pending jobs across specified queues.
retryDeadLetter(String jobId) Future<bool>
Retries a dead-letter job by its jobId, moving it back to the queue.
stopWorker() Future<void>
Stops the background worker gracefully.
toString() String
A string representation of this object.
inherited
work({List<String> queues = const ['default'], int concurrency = 1, int maxJobsPerSecond = 0, Duration pollInterval = const Duration(milliseconds: 500), JobEventCallback? onProcess, JobEventCallback? onComplete, JobEventCallback? onRetry, JobEventCallback? onFail, JobEventCallback? onTimeout}) Future<void>
Starts a background worker to process jobs.

Operators

operator ==(Object other) bool
The equality operator.
inherited