InMemoryDriver class

High-performance in-memory queue driver

Perfect for:

  • Development and testing
  • Short-lived jobs that don't need persistence
  • High-throughput scenarios
  • Jobs that can be lost on restart

Features:

  • Fast O(1) enqueue and dequeue
  • Priority queue support
  • Delayed job execution
  • Full metrics tracking
  • Middleware support
  • Dead letter queue integration

Example:

final driver = InMemoryDriver(
  config: DriverConfig(
    name: 'memory',
    trackMetrics: true,
    useDLQ: true,
  ),
  metrics: metrics,
  dlqHandler: dlqHandler,
  middleware: middleware,
);

await driver.push(SendEmailJob('user@example.com'));
await driver.process();
Inheritance

Constructors

InMemoryDriver({required DriverConfig config, QueueMetrics? metrics, FailedJobHandler? dlqHandler, QueueMiddlewarePipeline? middleware})

Properties

config DriverConfig
finalinherited
dlqHandler FailedJobHandler?
finalinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Check if queue is empty
no setter
isNotEmpty bool
Check if queue has jobs
no setter
metrics QueueMetrics?
finalinherited
middleware QueueMiddlewarePipeline?
finalinherited
pendingJobs List<JobContext>
Get all pending jobs (for testing/inspection)
no setter
pendingJobsCount int
Get count of pending jobs
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Clear all jobs (for testing)
override
createJobContext(QueueJob job, {Duration? delay}) JobContext
Create job context
inherited
dispose() Future<void>
Dispose resources
inherited
executeJob(JobContext context) Future<void>
Execute job with full lifecycle
inherited
generateJobId() String
Generate unique job ID
inherited
getStats() Future<Map<String, dynamic>>
Get driver statistics
override
handleJobFailure(JobContext context) Future<void>
Handle job failure with retry logic
inherited
isHealthy() Future<bool>
Health check
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onJobCompleted(JobContext context) Future<void>
Called when a job is successfully completed
inherited
onJobFailed(JobContext context) Future<void>
Called when a job fails permanently
inherited
onJobRetried(JobContext context) Future<void>
Called when a job is retried
inherited
process() Future<void>
Starts processing queued jobs.
override
push(QueueJob job, {Duration? delay}) Future<void>
Pushes a QueueJob to the queue with optional delay.
override
retryJob(JobContext context, {required Duration delay}) Future<void>
Retry a failed job
override
toString() String
A string representation of this object.
inherited

Operators

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