[GRM-287] - Tasks scheduled by the scheduler seem to either behave erratically or don't run at all. #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GRM-287
The reason this is necessary is because once the first clock synchronisation callback is fired, the timer will become locked to a single point in time. The
break
statement will cause the innerfor
loop to complete, as shown below, but will not cause any update to the cachednow
value (without the addition of the newnow
line).https://github.com/team-rocos/cron/blob/966ed6863c9e1311d6e9e9244a21b06e257850ba/cron.go#L354-L359
This means that each time we recalculate the time because of a time synchronisation, the
now
value will always be the same and since the job time is not changing, the two times will always return the same positive difference, never getting any closer to each other. As can be seen on the code block below- in particular line 312. This obviously doesn't mean the timer will never fire, it just means that the remaining time to start a task must be less than the duration until the next time synchronisation.https://github.com/team-rocos/cron/blob/966ed6863c9e1311d6e9e9244a21b06e257850ba/cron.go#L302-L315