QueueJob class abstract

Represents a job that can be queued and processed asynchronously.

Just extend QueueJob and implement handle()!

Simple Jobs (Memory/Sync drivers)

For memory and sync drivers, no serialization is needed:

class SendEmailJob extends QueueJob {
  final String email;

  SendEmailJob(this.email);

  @override
  Future<void> handle() async {
    await sendEmail(email);
  }
}

// Dispatch it
queueManager.dispatch(SendEmailJob('user@example.com'));

Serializable Jobs (File/Redis/Database drivers)

For persistent drivers, jobs must be serializable and registered:

class SendEmailJob extends QueueJob with SerializableJob {
  final String email;

  SendEmailJob(this.email);

  factory SendEmailJob.fromJson(Map<String, dynamic> json) {
    return SendEmailJob(json['email'] as String);
  }

  @override
  Map<String, dynamic> toJson() => {'email': email};

  @override
  Future<void> handle() async {
    await sendEmail(email);
  }
}

// Register at startup
QueueJobRegistry.register('SendEmailJob', (json) => SendEmailJob.fromJson(json));

// Then dispatch as normal
queueManager.dispatch(SendEmailJob('user@example.com'));
Implementers
Available extensions

Constructors

QueueJob()

Properties

displayName String
Optional: Job display name for logging/debugging. Defaults to the class name.
no setter
hashCode int
The hash code for this object.
no setterinherited
maxRetries int
Optional: Number of times to retry this job on failure. Default is 3 attempts.
no setter
priority JobPriority

Available on QueueJob, provided by the PriorityQueueJob extension

Get job priority (default: normal)
no setter
queue String
Optional: Queue name to dispatch this job to. Default is 'default'.
no setter
retryDelay Duration
Optional: Delay between retry attempts. Default is 30 seconds.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldRetry bool
Optional: Whether this job should be retried on failure. Default is true.
no setter
timeout Duration?
Optional: Job timeout. Job will be killed if it takes longer. Default is no timeout.
no setter

Methods

handle() Future<void>
Called when the job is executed. Put your job logic here.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Returns the job data as a JSON-encoded string.
toString() String
A string representation of this object.
inherited

Operators

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