FileStorageDriver class
Persistent file-based queue driver
Stores jobs in JSON files on disk for persistence across restarts. Perfect for:
- Small to medium applications
- Jobs that must survive restarts
- Simple deployment without Redis/Database
- Development and testing with persistence
Features:
- Persistent storage
- Automatic recovery on restart
- Job serialization/deserialization
- Atomic file operations
- Lock-free design
- Full metrics tracking
- Middleware support
- Dead letter queue integration
Example:
// Register serializable jobs
QueueJobRegistry.register('SendEmailJob',
(json) => SendEmailJob.fromJson(json));
final driver = FileStorageDriver(
config: DriverConfig(
name: 'file',
driverSpecificConfig: {
'storagePath': './storage/queue',
},
),
metrics: metrics,
dlqHandler: dlqHandler,
);
await driver.push(SendEmailJob('user@example.com'));
await driver.process();
- Inheritance
-
- Object
- BaseQueueDriver
- FileStorageDriver
Constructors
- FileStorageDriver({required DriverConfig config, QueueMetrics? metrics, FailedJobHandler? dlqHandler, QueueMiddlewarePipeline? middleware, String? storagePath})
Properties
- config → DriverConfig
-
finalinherited
- dlqHandler → FailedJobHandler?
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- metrics → QueueMetrics?
-
finalinherited
- middleware → QueueMiddlewarePipeline?
-
finalinherited
-
pendingJobsCount
→ Future<
int> -
Get pending job count
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storagePath → String
-
final
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
override
-
executeJob(
JobContext context) → Future< void> -
Execute job with full lifecycle
inherited
-
generateJobId(
) → String -
Generate unique job ID
inherited
-
getPendingJobs(
) → Future< List< JobContext> > - Get all pending jobs (for inspection)
-
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