Skip to content

Commit

Permalink
If there is no scheduled last date call setInitialNextDate with .now (
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Nov 13, 2024
1 parent b9288b2 commit 0cf8786
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Sources/Jobs/Scheduler/JobSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ public struct JobSchedule: MutableCollection, Sendable {
var jobSchedule = self.jobSchedule
// Update next scheduled date for each job schedule based off the last scheduled date stored
do {
if let date = try await self.jobQueue.getMetadata(.jobScheduleLastDate) {
self.jobQueue.logger.debug("Last scheduled date \(date).")
for index in 0..<jobSchedule.count {
jobSchedule[index].nextScheduledDate = jobSchedule[index].schedule.setInitialNextDate(after: date) ?? .distantFuture
}
let date: Date
if let lastDate = try await self.jobQueue.getMetadata(.jobScheduleLastDate) {
self.jobQueue.logger.debug("Last scheduled date \(lastDate).")
date = lastDate
} else {
date = .now
}
self.jobQueue.logger.debug("Last scheduled date \(date).")
for index in 0..<jobSchedule.count {
jobSchedule[index].nextScheduledDate = jobSchedule[index].schedule.setInitialNextDate(after: date) ?? .distantFuture
}
} catch {
self.jobQueue.logger.error("Failed to get last scheduled job date.")
Expand Down

0 comments on commit 0cf8786

Please sign in to comment.