Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule Logic Fix #3327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Schedule Logic Fix #3327

wants to merge 1 commit into from

Conversation

ShellyWEI
Copy link
Collaborator

@ShellyWEI ShellyWEI commented Aug 31, 2023

This reverts commit 6db7500. In this commit, we introduce a logic to categorize a trigger as expired trigger by examining the calculated nextCheckTime is before NOW. However there are twice update in the schedule loop when the current schedule is right on time to trigger action. In this case, right after trigger actions, the reset time checker is invoked where the trigger's nextCheckTime will be updated to be next valid trigger time after current time; while at the end of the loop, there is also trigger.updateNextCheckTime() to be called, and because the new current time is greater than the last update's current time, it is possible, the updated nextCheckTime is already passed the new current time, and result in catogorizing trigger as EXPIRED trigger

Details
This PR is to remove the second trigger.updateCheckTime() for several reasons:

  1. Trigger's metadata would be updated and stored in DB anyways, we don't need frequently update nextCheckTime in one minute (scan interval) basis;
  2. Trigger's triggerContition is already relying on NOW>nextCheckTime to trigger action, it means, in every loop we would check if nextCheckTime reaches now, if nextCheckTime is 10:00:00.000 and the check happens at 09:59:59.999, but after several lines when we force to update, now is 10:00:00.001, and we have to find next valid time after now, it would skip 10:00:00.000 to find the next valid value, so 10:00:00 can not be used to trigger actions. To conclude that, if a trigger's status is READY, we only need to update nextCheckTime after the recorded "nextCheckTime" is used to trigger action, otherwise, if the condition is not met, we're not supposed to update nextCheckTime by default, if it is falling too much cycles, the missed schedule logic would capture all the skipped checkTime and only allow the closet-to-now checkTime to remain to be checked.

Test
Add two unit tests to ensure the expiration works properly as expected, and normal trigger should not get impacted.
Schedule System's unit test is normally hard to target on one single corner cases, as the logic is relying on "NOW" (the moment that flipping the trigger's check time), it's usually hard to define if the corner case would happen exactly in this run, we're more hoping the iterations itself would hit the cornor case if possible. Take one use case as an example, we expect the current time is right before the trigger time in several interations to monitor it's keeping performing as it is, but we could only precisely control the first check time, and hard to control later updates because the testing interval is different than the real time interval, if we mock everything to match real time, it would make the test lengthy and slow.

This reverts commit 6db7500. In this commit, we introduce a logic to categorize a trigger as expired trigger by examining the calculated nextCheckTime is before NOW.
However there are twice update in the schedule loop when the current schedule is right on time to trigger action.
In this case, right after trigger actions, the reset time checker is invoked where the trigger's nextCheckTime will be updated to be next valid trigger time after current time; while at the end of the loop, there is also trigger.updateNextCheckTime() to be called, and because the new current time is greater than the last update's current time, it is possible, the updated nextCheckTime is already passed the new current time, and result in catogorizing trigger as EXPIRED trigger

Details
This PR is to remove the second trigger.updateCheckTime() for several reasons:
1. Trigger's metadata would be updated and stored in DB anyways, we don't need frequently update nextCheckTime in one minute (scan interval) basis;
2. Trigger's triggerContition is already relying on NOW>nextCheckTime to trigger action, it means, in every loop we would check if nextCheckTime reaches now, if nextCheckTime is 10:00:00.000 and the check happens at 09:59:59.999, but after several lines when we force to update, now is 10:00:00.001, and we have to find next valid time after now, it would skip 10:00:00.000 to find the next valid value, so 10:00:00 can not be used to trigger actions.
To conclude that, if a trigger's status is READY, we only need to update nextCheckTime after the recorded "nextCheckTime" is used to trigger action, otherwise, if the condition is not met, we're not supposed to update nextCheckTime by default, if it is falling too much cycles, the missed schedule logic would capture all the skipped checkTime and only allow the closet-to-now checkTime to remain to be checked.

Test
Add two unit tests to ensure the expiration works properly as expected, and normal trigger should not get impacted.
Schedule System's unit test is normally hard to target on one single corner cases, as the logic is relying on "NOW" (the moment that flipping the trigger's check time), it's usually hard to define if the corner case would happen exactly in this run, we're more hoping the iterations itself would hit the cornor case if possible. Take one use case as an example, we expect the current time is right before the trigger time in several interations to monitor it's keeping performing as it is, but we could only precisely control the first check time, and hard to control later updates because the testing interval is different than the real time interval, if we mock everything to match real time, it would make the test lengthy and slow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant