Prevent multiple execution of commands scheduled in the past #121
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
ScheduledMessage.RecalculateStartAfter()
logic to advanceStartAfter
until it moves past the current dateStartAfter
times are expected to be UTCScheduler.LoadState
to callRecalculateStartAfter()
on loaded schedules whoseStartAfter
is before the current timehidden
parameterless constructor forLogger
, to enable some mockingRelated Issue
#120
Motivation and Context
If a command was originally scheduled several months ago and the bot is restarted, a very large number of executions will occur very quickly. Depending on the command scheduled, this may prove problematic.
How Has This Been Tested?
Added unit tests to
ScheduledMessages.tests.ps1
to check the behavior ofRecalculateStartAfter()
with dates in the future and the past.Added unit tests (and some hacky mocks) in
Scheduler.tests.ps1
to check the behavior ofScheduler.LoadState()
when a schedule with aStartAfter
in the past is loaded.Manually started a bot and ran
!newschedule --command 'help' --interval minutes --value 5 --startafter '2018-10-01 12:25pm'
and verified that only one response was produced immediately. Restarted the bot and verified that no responses were produced on schedule load.Screenshots (if appropriate):
Types of changes
Checklist: