benkuly
09/28/2021, 7:05 PMJannis
09/28/2021, 9:37 PMval schedule = Schedule.exponential(x.milliseconds).or(Schedule.spaced(5.minutes))
while (true) {
schedule.retry { myTask() }
}
Should work.
How does this work?
Well the magic here is the or
combinator which combines two schedules, continues when one of them continue and takes the smaller delay of the two. So when the first schedule exceeds 5 mins delay it will take the second and as both are infinite they run forever.
You can also manually make the first schedule fail with doWhileOutput { it < 5.minutes.inNanoseconds }
(the output of the exponential
schedule is it's current delay at each iteration) so we can stop it by applying this condition, but because or
uses the smaller delay anyway this is not necessary.
Also the reset is simply another iteration on the while loop, which just throws away the schedule state.
Schedule
can do even more complex things quite trivially, but it can be a bit hard to understand at first, so feel free to ask about how stuff works :)benkuly
09/29/2021, 5:42 AM