SerializableJob mixin
Mixin for jobs that need to persist their constructor arguments.
Implement serialize to encode your job's data, and use a JobFactory in DatabaseQueueDriver.registerJobFactory to decode it.
class SendEmailJob extends Job with SerializableJob {
final String to;
SendEmailJob(this.to);
@override
String get name => 'SendEmailJob';
@override
String serialize() => jsonEncode({'to': to});
@override
Future<void> handle() async { ... }
}
- Superclass constraints
Properties
- attempts ↔ int
-
How many times this job has been attempted so far.
getter/setter pairinherited
- availableAt ↔ DateTime?
-
When this job should next be processed (for delayed/retry scheduling).
getter/setter pairinherited
- canRetry → bool
-
Returns true if this job can be retried.
no setterinherited
- createdAt ↔ DateTime
-
When this job was first created.
latefinalinherited
- currentRetryDelay → Duration
-
Calculates the delay for the current retry attempt using exponential backoff.
no setterinherited
- finishedAt ↔ DateTime?
-
When this job finished processing (completed or permanently failed).
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ String
-
A unique ID generated for each job instance.
latefinalinherited
- isAvailable → bool
-
Returns true if this job is ready to be processed now.
no setterinherited
- lastError ↔ Object?
-
The error from the last failed attempt, if any.
getter/setter pairinherited
- lastStackTrace ↔ StackTrace?
-
The stack trace from the last failed attempt, if any.
getter/setter pairinherited
- maxRetries → int
-
Maximum number of times this job can be retried after failure.
no setterinherited
- name → String
-
The logical name of this job, used for logging and tracking.
no setterinherited
- queue → String
-
The queue this job should be dispatched to. Defaults to
'default'.no setterinherited - retryDelay → Duration
-
Base delay between retries. Actual delay increases exponentially.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status ↔ JobStatus
-
The current status of this job.
getter/setter pairinherited
- timeout → Duration?
-
Maximum time a single job execution is allowed to run.
no setterinherited
Methods
-
handle(
) → Future< void> -
The work this job performs. Override in your subclass.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFailure(
Object error, StackTrace stackTrace) → Future< void> -
Called when handle throws an exception. Override for custom error handling.
inherited
-
onPermanentFailure(
Object error, StackTrace stackTrace) → Future< void> -
Called after the job has exhausted all retries. Override for dead-letter logic.
inherited
-
serialize(
) → String - Serializes this job's data to a string (typically JSON).
-
toJson(
) → Map< String, dynamic> -
Converts the job to a JSON-compatible map.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited