When a command is scheduled with an IntervalMS and a StartAfter value, it will execute on the StartAfter time and each subsequent time the IntervalMS elapses after the StartAfter.
If the StartAfter time is in the past and the schedule has just been created, the command will execute immediately and will execute again on each passing of the IntervalMS.
For example, if a new command is scheduled to run every hour at five minutes after the hour, with a StartAfter of 3:05 PM, and the current time is 3:15 PM, the command would execute immediately. Subsequent runs would take place at 4:05 PM, 5:05 PM, etc.
If the bot is brought online with a schedule containing a StartAfter in the past, the command will execute on each passing of the IntervalMS.
For example, if a command is scheduled to run every hour at five minutes after the hour, with a StartAfter of 3:05 PM, and the bot is brought online at 3:15 PM, the command would next run at 4:05 PM.
Current Behavior
Whenever scheduled commands are processed (either by new registration or by loading a schedules.psd1 file), the command is executed as many times as IntervalMS have elapsed between the StartAfter and the current time.
For example, if a command was originally scheduled to run with --Interval days --Value 1 --StartAfter '2018-01-01' and the bot is started or the command is registered on 2018-01-05, the command will execute 5 times immediately after the schedule is processed.
Possible Solution
Prevent RecalculateStartAfter() from producing new StartAfter values that are in the past--advance the initial StartAfter value by as many IntervalMS as are required to take it past the current time.
Have Scheduler call RecalculateStartAfter() for any stored schedules it loads whose StartAfter is in the past.
Steps to Reproduce (for bugs)
Run the command !newschedule --command 'help' --interval minutes --value 5 --startafter '2018-10-01 12:25pm'
Should see a large number of !help results outputted to the channel
Context
I have some long-standing scheduled commands that do some monitoring and report statuses out to a channel. They were originally scheduled in June, and don't need to run a few hundred times when I reboot the server.
Your Environment
Module version used: 0.11.0
Operating System and PowerShell version: Windows Server 2012, PowerShell 5.1
Expected Behavior
When a command is scheduled with an
IntervalMS
and aStartAfter
value, it will execute on theStartAfter
time and each subsequent time theIntervalMS
elapses after theStartAfter
.If the
StartAfter
time is in the past and the schedule has just been created, the command will execute immediately and will execute again on each passing of theIntervalMS
.StartAfter
of 3:05 PM, and the current time is 3:15 PM, the command would execute immediately. Subsequent runs would take place at 4:05 PM, 5:05 PM, etc.If the bot is brought online with a schedule containing a
StartAfter
in the past, the command will execute on each passing of theIntervalMS
.StartAfter
of 3:05 PM, and the bot is brought online at 3:15 PM, the command would next run at 4:05 PM.Current Behavior
Whenever scheduled commands are processed (either by new registration or by loading a
schedules.psd1
file), the command is executed as many times asIntervalMS
have elapsed between theStartAfter
and the current time.--Interval days --Value 1 --StartAfter '2018-01-01'
and the bot is started or the command is registered on2018-01-05
, the command will execute 5 times immediately after the schedule is processed.Possible Solution
Prevent
RecalculateStartAfter()
from producing newStartAfter
values that are in the past--advance the initialStartAfter
value by as manyIntervalMS
as are required to take it past the current time.Have
Scheduler
callRecalculateStartAfter()
for any stored schedules it loads whoseStartAfter
is in the past.Steps to Reproduce (for bugs)
!newschedule --command 'help' --interval minutes --value 5 --startafter '2018-10-01 12:25pm'
!help
results outputted to the channelContext
I have some long-standing scheduled commands that do some monitoring and report statuses out to a channel. They were originally scheduled in June, and don't need to run a few hundred times when I reboot the server.
Your Environment