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);
}
}
}

 

Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
[Solved] Err_Http2_Protocol_Error

[Solved] err_http2_protocol_error

Table of Contents Hide Solution err_http2_protocol_errorScenario 1: Low Disk SpaceScenario 2: Gzip double compressionScenario 3: Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR after upgrading to VS 2019 16.10.0 (and 16.10.1) The err_http2_protocol_error…
View Post