add jitter and tests

This commit is contained in:
Alex Holliday committed 2026-06-16 11:34:58 -07:00
1 parent f7211711ce
commit 699883e0b1
2 files changed
+7 -5

No files matched your search

@@ -88,9 +88,9 @@ class MongoJobsRepository implements IJobsRepository {
let nextScheduledAt = scheduledRunAt + intervalMs;
// If the job fell behind, skipped missed runs
// If the job fell behind, skip the missed runs. Spread the next run with jitter to avoid a herd
if (nextScheduledAt <= now) {
nextScheduledAt = now + intervalMs;
nextScheduledAt = now + intervalMs + Math.floor(Math.random() * intervalMs);
}
const res = await JobModel.updateOne(