markExecuted method
Future<void>
markExecuted(
- String id, {
- required DateTime scheduledFor,
- required DateTime executedAt,
- Duration? jitter,
- String? lastError,
- bool success = true,
- Duration? runDuration,
- DateTime? nextRunAt,
- Duration? drift,
override
Updates execution metadata for the entry id.
Implementation
@override
Future<void> markExecuted(
String id, {
required DateTime scheduledFor,
required DateTime executedAt,
Duration? jitter,
String? lastError,
bool success = true,
Duration? runDuration,
DateTime? nextRunAt,
Duration? drift,
}) async {
final state = _entries[id];
if (state == null) return;
final resolvedSuccess = success && lastError == null;
final updatedEntry = state.entry.copyWith(
lastRunAt: executedAt,
lastError: lastError,
lastJitter: jitter,
lastSuccessAt: resolvedSuccess ? executedAt : state.entry.lastSuccessAt,
lastErrorAt: resolvedSuccess ? state.entry.lastErrorAt : executedAt,
totalRunCount: state.entry.totalRunCount + 1,
drift: drift ?? state.entry.drift,
);
var next = nextRunAt;
var enabled = updatedEntry.enabled;
if (next == null && enabled) {
try {
next = _calculator.nextRun(
updatedEntry,
executedAt,
includeJitter: false,
);
} on Exception {
next = executedAt;
}
}
if (updatedEntry.expireAt != null &&
!executedAt.isBefore(updatedEntry.expireAt!)) {
enabled = false;
}
if (updatedEntry.spec is ClockedScheduleSpec) {
final spec = updatedEntry.spec as ClockedScheduleSpec;
if (spec.runOnce && !executedAt.isBefore(spec.runAt)) {
enabled = false;
}
}
next ??= executedAt;
final nextVersion = state.entry.version + 1;
state
..entry = updatedEntry.copyWith(
nextRunAt: next,
enabled: enabled,
version: nextVersion,
)
..nextRun = next
..locked = false;
}