fix: don't advance lastDate() for ticks skipped by waitForCompletion#1068
Open
chatman-media wants to merge 1 commit into
Open
fix: don't advance lastDate() for ticks skipped by waitForCompletion#1068chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
When `waitForCompletion` is enabled and a callback is still running, the scheduled tick is skipped in `fireOnTick()`. However `lastExecution` was assigned right before calling `fireOnTick()` (and in `runOnInit`/threshold paths), so it advanced even when no callback actually ran. This made `lastDate()`/`lastExecution` report the time of the last tick check rather than the last real execution, contradicting their documented meaning. Move the `lastExecution` assignment into `fireOnTick()`, after the already-running guard, so it only updates when the callback truly fires. Closes kelektiv#1048
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
When
waitForCompletionis enabled and a callback is still running, the scheduled tick is skipped early infireOnTick():However,
this.lastExecution = new Date()was assigned at the call sites before invokingfireOnTick()(the normal timer path, plus therunOnInitand threshold-"execute immediately" paths). As a resultlastExecutionadvanced on every tick check, even when the callback was skipped because the previous one was still running.This means
lastDate()/lastExecutionreported the moment of the last tick check rather than the last real execution, which contradicts their documented meaning (lastDate: Provides the last execution date.) and is inconsistent withnextDate()/nextDates()which describe when anonTickactually activates.Related Issue
Closes #1048
Motivation and Context
The fix moves the
lastExecutionassignment intofireOnTick(), placed right after the already-running guard, so it is only updated when a callback truly fires. The four call-site assignments are removed (therunOnInit, normal-tick, and threshold paths all callfireOnTick()immediately after, so firing behaviour is unchanged; the skipped path no longer advances the timestamp).This keeps the existing documented semantics intact — confirmed by the pre-existing tests "should give the correct last execution date" and the #710 regression test, both of which still pass.
How Has This Been Tested?
Added a regression test under the
waitForCompletion and job status trackingsuite. With a 1.5s callback on a* * * * * *schedule andwaitForCompletion: true:lastDate()is1000lastDate()must still be1000(was2000before this fix)lastDate()is3000The test fails on
main(Expected: 1000, Received: 2000) and passes with the fix. Full suite:162 passed. ESLint + Prettier clean,tscbuild clean. Ran withTZ='Europe/Paris'as configured.Types of changes
Checklist:
!after the type/scope in the title (n/a — not a breaking change).