Skip to content

ScheduledCommands fire off every IntervalMS from the time the schedule is created, not when the command is scheduled to run #85

@JasonNoonan

Description

@JasonNoonan

Expected Behavior

My coworker schedules the !dilbert command to fire every day at 7AM. I expect that on the next cycle after the scheduled time has passed, the command will be fired off.

Current Behavior

When the ScheduledCommand is created and initialized, a StopWatch object is created and the timer is started. Every cycle, the StopWatch is checked to see if it is greater than the defined IntervalMS. This results in (for instance) a command that is scheduled to run at 7AM every day instead firing off daily at 2:45PM because that is when I happened to create the scheduled command.

Possible Solution

Modify the Scheduler logic so that the HasExpired method checks to see if the StartAfter property is less than the current date (which is currently being done after the IntervalMS check in the module). If so, fire off the command.

Modify the RestartTimer function to modify the StartAfter property with $this.StartAfter.AddMilliseconds($IntervalMS) so that the next run triggers correctly

Steps to Reproduce (for bugs)

  1. Create a scheduled command, with a "StartAfter" value that is different from the increment amount
  2. Wait for the command to fire off
  3. Observe that the command is fired off $IntervalMS milliseconds after you created the command, not at the time you configured it to fire off

Your Environment

  • Module version used: 0.10.2
  • Operating System and PowerShell version: Windows 10 (1803) - PowerShell v5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions