Kentico CMS 6.0 Developer's Guide

Configuring task execution

Configuring task execution

Previous topic Next topic Mail us feedback on this topic!  

Configuring task execution

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

This topic explains how to configure execution of scheduled tasks.

 

Configuring execution by Kentico CMS application or external Windows service

 

Scheduled tasks can either be executed by the Kentico CMS application itself, or by a dedicated Windows service. Executing tasks using the Windows service is recommended for resource‑consuming tasks because their execution by the Windows service does not affect performance of the Kentico CMS application.

 

For tasks to be executed by the Windows service, the service needs to be installed and running and the Use external service setting in Site Manager -> Settings -> System needs to be enabled. With these pre-conditions met, you can enable the Use external service option in each task's editing interface in Site Manager -> Administration -> Scheduled tasks. Tasks with the Use external service option disabled will still be executed by the application itself. If the Use external service setting in Site Manager -> Settings -> System is disabled, even tasks with this option enabled are processed by the application itself.

 

 

 

Scheduling reliability

 

Since tasks execution by the application runs within the ASP.NET process, tasks will not be executed by the application if it is not running. This happens when the process is recycled without being started again (after a long period of website inactivity).

 

If you want to run the scheduling reliably, it's recommended to execute these tasks using the Windows service.

 

If you still want to execute them by the application, you need to ensure that your website is always running. You can do that by using some utility or an external service that requests the home page of your website on a regular basis.

 

 

 

 

Resolving context macros when executing tasks by the Windows service

 

Tasks that are executed by the Windows service can't resolve macros dependent on application context (e.g. {%ApplicationPath%}). This happens due to the fact that the context is not available when tasks are executed outside the application. Therefore, it is recommended to execute such tasks by the application.

 

 

Configuring execution intervals

 

There are two types of settings which determine when tasks should be executed. First, you can configure a time period after which tasks should be ready for execution. This can be configured separately for each individual task. Then, you can configure a time period after which the application or the Windows service checks if there are any tasks ready for execution. All tasks that are ready for execution during this check are subsequently executed.

 

Task interval

 

Individual tasks have a specified time interval after which they should be considered as ready to be executed. This interval is defined separately for each scheduled task by means of the Task interval settings in the task's editing interface in Site Manager -> Administration -> Scheduled tasks.

 

Application scheduler interval

 

The Application scheduler interval setting in Site Manager -> Settings -> System determines the time interval after which the application checks if there are any tasks ready to be executed. This setting only applies to tasks that are configured to be executed by the application itself, not by the Windows service. The values are entered in seconds and the checks and execution can be completely disabled by setting the value to 0. The minimum possible value is 30 seconds.

 

By default, the application performs the check at the end of standard page requests. This means that tasks are executed only when user activity on your website is generating requests. Because of this, the Application scheduler interval setting actually sets the minimum interval between these checks.

 

Alternatively, the scheduler can be configured to process tasks regularly according to an automatic internal timer, regardless of website activity. In this case, the Application scheduler interval setting sets the precise interval between these checks. This can be done by adding the CMSUseAutomaticScheduler key into the /configuration/appSettings section of your web.config file, as shown below.

 

<add key="CMSUseAutomaticScheduler" value="true" />

 

Service scheduler interval

 

The Service scheduler interval setting in Site Manager -> Settings -> System determines the time interval after which the Windows service checks if there are any tasks ready to be executed. This setting only applies to tasks that are configured to be executed by the Windows service, not by the application itself. The value sets the precise interval between the checks, the same as when using the automatic scheduler, but with higher reliability is ensured and less application load generated. The values are entered in seconds and the checks and execution can be completely disabled by setting the value to 0.

 

Additional low-level settings

 

Additional low-level scheduler settings can be done by adding the keys listed in the Scheduler settings section of Appendix B - Web.config parameters.