addJob method
Add new job into the queue
AsyncJob (Function(PreviousResult dynamic) job) will provide previous job's result to use in the next job if you wish to use,
otherwise just ignore it using _.
retryTime set the time that this job should retry if failed, default to 1,
set retryTime to -1 will make it retry infinitely, until job is done "be careful what you wish for!"
setting retryTime does not make the job auto retry
you must explicitly call retry when adding job.
label must be unique, this can be use to get the AsyncNode that contains the related job
will throw DuplicatedLabelException if you the label is already in the queue
description description for the job
Implementation
@override
void addJob(
AsyncJob job, {
Object? label,
String? description,
int retryTime = 1,
}) {
if (isClosed) {
return _emitEvent(QueueEventType.violateAddWhenClosed);
}
final newNode = AsyncNode(
job: job,
maxRetry: retryTime,
label: label ?? DateTime.now().toIso8601String(),
description: description,
);
if (_map.containsKey(newNode.label)) {
if (allowDuplicate) {
_updateQueueMap(newNode.label);
_enqueue(newNode);
} else {
if (throwIfDuplicate) {
throw DuplicatedLabelException(
"A job with this label already exists",
);
}
}
} else {
_enqueue(newNode);
_updateQueueMap(newNode.label);
}
if (_autoRun) start();
}