poshbotio / PoshBot

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

Scheduled(once) command crashes bot trying to call StopTimer() #116

Closed gkingston closed 5 years ago

gkingston commented 5 years ago

Expected Behavior

Scheduled command runs one time

Current Behavior

I scheduled the !status command to run one time a few mintues from my current time to see how scheduled tasks work. Looking at the logs, I believe it did run, but the whole bot crashed out after trying to remove the timer.

The command I ran: !new-scheduledcommand -command status -startafter '2018/09/21 08:08pm' -once

Relevant log section: {"DataTime":"2018-09-21 20:07:20Z","Class":"Bot","Method":"ProcessCompletedJobs","Severity":"Normal","LogLevel":"Info","Message":"Done processing command [Builtin:New-ScheduledCommand:0.11.0]","Data":{}} {"DataTime":"2018-09-21 20:08:00Z","Class":"Scheduler","Method":"<ScriptBlock>","Severity":"Normal","LogLevel":"Info","Message":"Timer reached on scheduled command [cdcd09615e154e88b3b5ac300fb65ed8]","Data":{}} {"DataTime":"2018-09-21 20:08:00Z","Class":"Bot","Method":"Start","Severity":"Error","LogLevel":"Info","Message":"Method invocation failed because [ScheduledMessage] does not contain a method named 'StopTimer'.","Data":{"CommandName":"ForEach-Object","Message":"Method invocation failed because [ScheduledMessage] does not contain a method named 'StopTimer'.","TargetObject":null,"Position":"At C:\\Program Files\\PowerShell\\Modules\\PoshBot\\0.11.0\\PoshBot.psm1:2589 char:55\n+ ... $messages = $this.Schedules.GetEnumerator() | Foreach-Object {\r\n+ ~~~~~~~~~~~~~~~~","CategoryInfo":"InvalidOperation: (:) [ForEach-Object], RuntimeException","FullyQualifiedErrorId":"MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand"}} {"DataTime":"2018-09-21 20:08:00Z","Class":"Bot","Method":"Disconnect","Severity":"Normal","LogLevel":"Verbose","Message":"Disconnecting from backend chat network","Data":{}} {"DataTime":"2018-09-21 20:08:00Z","Class":"TeamsConnection","Method":"Disconnect","Severity":"Normal","LogLevel":"Info","Message":"Stopping Service Bus receiver","Data":{}} {"DataTime":"2018-09-21 20:08:05Z","Class":"Bot","Method":"Disconnect","Severity":"Normal","LogLevel":"Verbose","Message":"Disconnecting from backend chat network","Data":{}} {"DataTime":"2018-09-21 20:08:05Z","Class":"TeamsConnection","Method":"Disconnect","Severity":"Normal","LogLevel":"Info","Message":"Stopping Service Bus receiver","Data":{}}

Possible Solution

Not completely sure what the $_.Value.StopTimer() does on line 99 of Scheduler.ps1 as searching for StopTimer in this repository on github only shows that one file that calls it.

Steps to Reproduce (for bugs)

  1. Create a scheduled command with -once to run a few minutes into the future like: !new-scheduledcommand -command status -startafter '2018/09/21 11:18am' -once
  2. Bot will tell you it is scheduled successfully
  3. Wait a few minutes
  4. Check logs

Context

Your Environment

devblackops commented 5 years ago

@gkingston Commit d6f4b3e773ec6893f970e49e720c0cabaa4c05d8 revamped how the schedules are calculated and removed the StopTimer() method from the ScheduledMessage class but there is still a reference in the Scheduler class.

I'll fix. Sorry about that!