poshbotio / PoshBot

Powershell-based bot framework
MIT License
539 stars 108 forks source link

Prevent multiple execution of commands scheduled in the past #121

Closed AngleOSaxon closed 6 years ago

AngleOSaxon commented 6 years ago

Description

Related 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 of RecalculateStartAfter() with dates in the future and the past.

Added unit tests (and some hacky mocks) in Scheduler.tests.ps1 to check the behavior of Scheduler.LoadState() when a schedule with a StartAfter 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:

devblackops commented 6 years ago

Thanks @AngleOSaxon! 👍