Can Schedule be used to do the following: Do a job...
# arrow
b
Can Schedule be used to do the following: Do a job forever, but with an exponential backoff limited to 5min, which gets reset, when the job succeeds.
j
Something like:
Copy code
val 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 :)
🔝 3
b
Thank you for the excelent explenation :)