Job class abstract
Base class for all queueable jobs.
Extend this class and implement handle to define the work your job performs. Override maxRetries, retryDelay, timeout, and queue to control retry behavior, timeouts, and queue routing.
class SendEmailJob extends Job {
final String to;
final String subject;
SendEmailJob(this.to, this.subject);
@override
String get name => 'SendEmailJob';
@override
int get maxRetries => 3;
@override
Duration get timeout => Duration(seconds: 30);
@override
Future<void> handle() async {
await emailService.send(to, subject);
}
}
- Implementers
Properties
- attempts ↔ int
-
How many times this job has been attempted so far.
getter/setter pair
- availableAt ↔ DateTime?
-
When this job should next be processed (for delayed/retry scheduling).
getter/setter pair
- canRetry → bool
-
Returns true if this job can be retried.
no setter
- createdAt ↔ DateTime
-
When this job was first created.
latefinal
- currentRetryDelay → Duration
-
Calculates the delay for the current retry attempt using exponential backoff.
no setter
- finishedAt ↔ DateTime?
-
When this job finished processing (completed or permanently failed).
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ String
-
A unique ID generated for each job instance.
latefinal
- isAvailable → bool
-
Returns true if this job is ready to be processed now.
no setter
- lastError ↔ Object?
-
The error from the last failed attempt, if any.
getter/setter pair
- lastStackTrace ↔ StackTrace?
-
The stack trace from the last failed attempt, if any.
getter/setter pair
- maxRetries → int
-
Maximum number of times this job can be retried after failure.
no setter
- name → String
-
The logical name of this job, used for logging and tracking.
no setter
- queue → String
-
The queue this job should be dispatched to. Defaults to
'default'.no setter - retryDelay → Duration
-
Base delay between retries. Actual delay increases exponentially.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status ↔ JobStatus
-
The current status of this job.
getter/setter pair
- timeout → Duration?
-
Maximum time a single job execution is allowed to run.
no setter
Methods
-
handle(
) → Future< void> - The work this job performs. Override in your subclass.
-
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.
-
onPermanentFailure(
Object error, StackTrace stackTrace) → Future< void> - Called after the job has exhausted all retries. Override for dead-letter logic.
-
toJson(
) → Map< String, dynamic> - Converts the job to a JSON-compatible map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited