My goal of this Quick Tip is to help any Kentico developer out there who may run into a situation where neither the built-in Scheduled Tasks nor custom Scheduled Tasks are executing either manually or automatically. I actually ran into this situation twice in the last two weeks on projects that we are working on with Kentico CMS 7.0 at BizStream.
Not sure what a Scheduled Task in Kentico CMS is or can be used for? Check out this post from Bryan Soltis, Kentico MVP, on why he finds Scheduled Tasks so useful in Kentico.
At first I thought that it was just a problem with the Scheduled Task itself. After being called in to troubleshoot, and inspecting the list of tasks to see that not a single one was running, I ran the task manually from CMSSiteManager -> Administration -> Scheduled Tasks. As my colleague predicted, nothing happened. I mean nothing. There was not a single Event Log entry, no number of executions changed, no worker thread spawned, just plain nothing. This was not a simple problem.
My next idea on how to troubleshoot this situation was to check out how the Scheduled Task itself was configured. In the past, I have seen it where a Scheduled Task was not running as expected because the Task itself was configured to use the external Kentico Scheduling Service. With Kentico CMS Ultimate and Kentico EMS you can easily do that via the Use External Services checkbox inside of the task properties. In fact it is a nice way to ensure your Task runs on the exact time you want it to, and does not slow down the website itself, because it runs at the OS level and not inside of the ISS worker process that runs your Kentico site.
A problem can arise If this checkbox is turned on for a task, but the Windows Server that is running the Kentico installation does not have the Kentico Scheduling Service installed. This was not the case with my problem at the time. The setting was not turned on.
Since the Task itself was enabled, configured correctly, and the next run time was a future date I was a bit stumped. I tried executing the Task manually a few more times and checked the Threads tab of the Debug Administration page in Kentico to see if I could see the Task running. What is supposed to happen is that when a Task runs, it should spawn a thread and you should see it finish or at least try to execute on this tab.
Well nothing happened there either. Ok, up next I remembered that one of the sites had been upgraded from an earlier version of Kentico and that there was a rare case where upgraded sites had their Scheduler interval setting thrown off. Kentico MVP, Jeoren Fuerst, first reported it via Twitter. I thought that re-saving this setting could help. So I tried updating the value of the setting, saving and re-running the Task, but nothing changed and the Task would still not run.
Well now I was a little stumped. Basically all of the normal problems/issues with Scheduled Tasks had been exhausted. Since the Task in question was a Task that was associated to a Site in the Kentico installation, and not Global, I decided to check out the CMSDesk of that Site. And viola! At the very first attempt to navigate to the Site in Kentico, I was presented with the generic error message of Invalid Site.
Well that would explain it I thought to myself. After checking out how the Site had been setup I found the problem. The Site had a misspelling in the main Site Domain Name setting. A simple fat finger typo mistake had cost my colleague and I the better part of two hours. Yep, as soon as we updated the Site to have the correct Domain name (URL) all of the Scheduled Tasks started executing normally. Doh!! So in Summary I present the following steps on how to troubleshoot this situation.
How To Troubleshoot Scheduled Task Execution in Kentico CMS
Try following these steps:
Check the Event log for any errors.
- Fix any exceptions if found. Execute the task again. Most of the time this is the problem.
Check that the Scheduled Task runs manually.
- Execute the task manually via the green Play button. Watch the number of executions and ensure it increments when you manually run it.
If the number of executions does increment.
- This is a good thing, at least the task runs and completes. Now to figure out why it does not run automatically.
Check the Scheduler Interval Custom Setting in CMSSiteManager -> Settings
- Change the interval value to either higher or lower, re-save the setting and go back to step 1.
Check how the Task is set to run, via the External Scheduling Service or not.
- If Yes - ensure that the Scheduling Service is installed on your server. It won't work if you don't have this installed.
- If No - skip to step 5.
If the number of executions does NOT increment.
- This is not a good thing, and should be a rare case. Take a deep breath, and keep reading.
Ensure that the Site is valid,
- Check that the Site has a valid Site License at the URL that you are executing from with a valid Site Domain Name and/or Site Alias in CMSSiteManager
- Hopefully this was it, if you had an invalid site, correct it, run the task and go back to step 1.
If still no solution.
- Check the you have a valid web.config file from a clean Kentico CMS installation and make sure no lines are missing from the default configuration. WinMerge is my favorite tool for this. And this was found to be an issue on the other project I mentioned above in the summary. Having a good, clean web.config is incredibly important to Kentico.
- Step away, get a cup of coffee walk around your office for 5 minutes and come back.
- Feel better? Good, now start firing up Visual Studio to debug your project locally. Add a break point inside the Task itself or in the Application Startup event, and start debugging your project locally to make sure you hit this breakpoint. This will prove that the Task is executing or not.
- If all else fails.
So there you have it. This is how I would troubleshoot the problem of Scheduled Tasks not executing in Kentico CMS. I hope this Kentico CMS Quick Tip saves you some heartache if you ever run across this situation. Thanks for reading!