due method
Returns schedules that should run at or before now.
Implementation
@override
/// Returns schedules that should run at or before [now].
Future<List<ScheduleEntry>> due(DateTime now, {int limit = 100}) async {
final due =
_entries.values
.where(
(state) =>
!state.locked &&
state.entry.enabled &&
(state.entry.expireAt == null ||
state.entry.expireAt!.isAfter(now)) &&
!(state.entry.nextRunAt ?? state.nextRun).isAfter(now),
)
.toList()
..sort((a, b) => a.nextRun.compareTo(b.nextRun));
final selected = <ScheduleEntry>[];
for (final state in due.take(limit)) {
state
..locked = true
..entry = state.entry.copyWith(nextRunAt: state.nextRun);
selected.add(state.entry);
}
return selected;
}