How to Schedule Tasks on Sitecore?

Sitecore has its own task scheduler and we can schedule any tasks or jobs on Sitecore. The approach to schedule tasks on Sitecore is pretty simple. Follow the steps mentioned below and you should be able to schedule and run any tasks in Sitecore

How to Schedule Tasks on Sitecore?

Step 1: Login to Sitecore content editor and navigate to the Tasks section in the content tree.

Step 2: Create a folder under Tasks item and name it accordingly. In this example am naming it as MyTasksSchedules.

Step 3: The next step is to execute the tasks. We need to add the information about the task and the scheduling time in the web.config. This config should only be placed on the servers where you need to run the task.

If you are using Sitecore 8.1 and above then you would need to patch to the web.config manually. Create a config named SitecoreTasks.config and place it in the App_config/Include folder.

Add the below config section and provide the agent type properly. Agent type is nothing but the namespace and class name of the task you created.

<agent type="MyProject.Services.LogSomething" method="Run" interval="00:01:00">
<param desc="database">master</param>
<param desc="schedule root">/sitecore/system/Tasks/MyTasksSchedules</param>
<message>Hello, World!</message> 
<LogActivity>true</LogActivity>
</agent>

The configuration above tells Sitecore to run the Job every 1 minute. The polling frequency determines how often Sitecore checks for agents that it needs to invoke. You can control the polling frequency by setting the value of the /configuration/sitecore/scheduling/frequency element in the web.config file (in HH:mm:ss format). I like to set the polling frequency to half of the value of the smallest value of the interval attribute of all the agents defined in the web.config file.

The custom agent code can be created by creating a simple class that implements a method. The same needs to be registered in the web.config as shown above.

Eg:

namespace MyProject.Services
{
public class LogSomething
{
public string Message
{
get;
set;
}
public void Run()
{
Sitecore.Diagnostics.Log.Info(this + " : " + this.Message, this);
}
}
}

 

0 Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
XOR in Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are…
How To

How to configure Git proxy?

If you are working in the corporate company all the internet requests usually goes through the corporate firewall.…