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.
Overview
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.
Task Configuration
- 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
--spider
parameter and the URL to your page to run. Below is a sample line for a task path.
[sourcecode]
"C:\Program Files\wget-1.11.4-1-bin\bin\wget.exe" –spider http://mysite.com/obfuscated-folder/special-task.aspx
[/sourcecode]
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:
Pros
- 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
Cons
- 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)
Additional Reading
- 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