This should be trivial, but my brain is running into a brick wall tonight.
I have a process that will run once, then every n minutes of an hourly offset.
EG, 15 minutes means run on the hour (say, 1), then 1:15, 1:30, 1:45, etc.
If the execution interval is 15, the initial execution is at 1:07 and runs until 1:11, the wait for the next execution will be in 4 minutes.
If the execution interval is 15, the initial execution is at 1:07 and runs until 1:16, the wait for the next execution will be 14 minutes (execution times do not overlap).
So, after every run (of an varying length), how do we calculate the number of minutes to wait until the next execution?
I’m not putting any sample code in here, because I don’t have anything that will pass my unit tests (I’m not so brain-dead that I can’t write those !).
I’ve tagged this as C# since that’s what I’m coding in, but I would expect the solution to be language-agnostic.
Okay, just as I hit submit on the question, I had an epiphany.
Given
currentMinute>= 0 andexecutionInterval>= 1absolute-value((currentMinute modulo executionInterval) - executionInterval)or, in C#
return Math.Abs((currentMinute % executionInterval) - executionInterval);so far, my unit-tests are passing on this one. So, either it is correct, or I don’t have enough tests….