There are many blog posts out there about automating and scheduling Sitecore tasks. This post covers a scenario that I’ve used several times and just wanted to share. As John West mentions in All About Sitecore Scheduling Agents and Tasks, tasks defined in Sitecore and configured agents may not run on a site if the ASP.NET worker process has shut down due to inactivity to the site. This is often the case during off hours when you’d probably want to perform administrative tasks.
The scenario I often have is to rebuild the Lucene search indexes at off hours, usually around 3am, when the worker process can very well be shutdown due to inactivity. The process is simple: install Wget and configure a Windows scheduled task to call Wget to request a secret page on the site.
- Download the Windows version of Wget and install it on the server.
- Create a new Windows Scheduled Task in the Control Panel.
- Navigate to the Wget program for the task to run.
- Once you create the task, right-click it and select Properties.
- Modify the path of the task to include the
--spiderparameter and the URL to your page to run. Below is a sample line for a task path.
"C:\Program Files\wget-1.11.4-1-bin\bin\wget.exe" --spider http://mysite.com/obfuscated-folder/special-task.aspx
This is just one of many ways to automate running something and have it happen at a specific time of the day. Here are some pros and cons I can think of for this approach:
- Guaranteed to run at a specific time since it doesn’t rely on ticks in Sitecore
- Simple to setup and won’t require a config change and therefore won’t recycle an existing app
- Since a secret page is exposed via a public URL, you can manually run the code by hitting the page
- Isolated from the Sitecore app, and thus possibly forgotten if migrating a server
- Requires a specific page on the site to be requested, meaning a page with secret code would be exposed publicly (this can easily be fixed via permissions)
- All About Sitecore Scheduling Agents and Tasks
- Long Running Process Options
- Sitecore – Publish via Scheduled Task
- Use the sitecore jobs
- Run Sitecore scheduled task at the same time every day
- Running Scheduledtasks with the jobmanager in Sitecore