oneShotJitteredNextCronRunMs function
int?
oneShotJitteredNextCronRunMs(
- String cron,
- int fromMs,
- String taskId, [
- CronJitterConfig cfg = kDefaultCronJitterConfig,
Same as nextCronRunMs, minus a deterministic per-task lead time when the fire time lands on a minute boundary matching CronJitterConfig.oneShotMinuteMod.
One-shot tasks are user-pinned so delaying them breaks the contract, but firing slightly early is invisible and spreads the inference spike.
Implementation
int? oneShotJitteredNextCronRunMs(
String cron,
int fromMs,
String taskId, [
CronJitterConfig cfg = kDefaultCronJitterConfig,
]) {
final t1 = nextCronRunMs(cron, fromMs);
if (t1 == null) return null;
final dt = DateTime.fromMillisecondsSinceEpoch(t1);
if (dt.minute % cfg.oneShotMinuteMod != 0) return t1;
final lead =
cfg.oneShotFloorMs +
_jitterFrac(taskId) * (cfg.oneShotMaxMs - cfg.oneShotFloorMs);
return max(t1 - lead.round(), fromMs);
}