SerializableJob mixin

Mixin for jobs that need to be serialized (for file/Redis drivers)

Jobs using persistent drivers (file, Redis, database) need to be serializable so they can be stored and reconstructed later. This mixin provides a standard pattern for serialization.

Example:

class SendEmailJob extends QueueJob with SerializableJob {
  final String email;
  final String subject;
  final String body;

  SendEmailJob(this.email, this.subject, this.body);

  // Factory constructor for deserialization
  factory SendEmailJob.fromJson(Map<String, dynamic> json) {
    return SendEmailJob(
      json['email'] as String,
      json['subject'] as String,
      json['body'] as String,
    );
  }

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

  @override
  Future<void> handle() async {
    await EmailService.send(email, subject, body);
  }
}

// Register at application startup
QueueJobRegistry.register('SendEmailJob', (json) => SendEmailJob.fromJson(json));
Superclass constraints
Available extensions

Properties

displayName String
Optional: Job display name for logging/debugging. Defaults to the class name.
no setterinherited
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 setterinherited
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 setterinherited
retryDelay Duration
Optional: Delay between retry attempts. Default is 30 seconds.
no setterinherited
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 setterinherited
timeout Duration?
Optional: Job timeout. Job will be killed if it takes longer. Default is no timeout.
no setterinherited

Methods

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

Operators

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