While playing around with the schedules in the SystemAgent, it appears that you never really set the time for a schedule to run at. But rather you set the interval, and the next time it should run.
What happens if that next tie to run is missed? Like if the server was down. Does it immediately fire because the NextRunTime is in the past? As oppsed to waiting for the next desired time to run?
For example:
It’s Monday 3/11
A schedule is set to run daily, with the next run time being 3/12/2019 12:01 AM
Server is downed for maintenance at 3/11/2019 11:50 PM. And for whatever reason, isn’t brought back up until 3/12/2019 11:30 PM (the next day)
.
Does the “missed” next run happen at 3/12/2019 11:30 PM (give or take a few minutes for startup)?
Is the NextRunTime set to 3/13/2019 11:30 PM, or 3/13/2019 12:01 AM?
I’ve always wonder about his too, so I ran a little experiment. I created an hourly job to run a report. Then I shutdown the app pool to simulate an outage. Here’s what I found.
9:05 pm, agent runs report
9:30 pm, I shut down the app pool
10:05 pm, agent (obviously) does not run
10:30 pm, restart app pool
11:00 pm, go to bed
The next morning at 8:30 am I expected to see some type of activity. There was none. It never started running again. I then restarted the task agent as I didn’t restart this before. When I did that, the report immediately popped up. I then decided to wait until 9:05 am to see if it started up again. Not only did it start up, but all of remaining scheduled runs ran.
So after you restarted at task agent at 8:30, the schedule that should have ran at 10:05 was run, and then set to run next at 11:05. Since 11:05 had passed, run again, setting next run to 12:05.
This repeats until the next run is set to happen sometime in the future.
But that doesn’t add up to the fact that yours ran 23 times after 8:30 AM. I would have only expected 11 times (the 10:05 through 8:05 instances)
One concern I have is that the next run time is set as the LastRun + Interval. So This ensures that the process will always be run when the system gets back online. But has the shortfall of running multiple times - trying to “catchup” for the missed schedules.
I agree. I tried to take a closer look but I can’t come up with a reason why it ran so many times. And can you image what would happen if all of those missed schedule runs were mrp!
I know this is a bit old, but I had this exact situation happen over memorial weekend. Epicor went down sometime Saturday afternoon. So MRP did not run on Sunday and Monday. When I came in on Tuesday, I restarted the app pool. At that point nothing happened. Next I restarted the task agent. Immediately MRP began to run, but it did only run once. It did not run for every day Epicor was down.
The task scheduler doesn’t schedule individual instances. It only schedules the “next” instance.
It basically looks at the task’s NextRunTime (which includes the date), and if the current clock is passed that, then run the task now, and set the Next RunTime based on the schedule.