Configuring scheduled task execution

This page explains how to configure execution of scheduled tasks. Scheduled tasks can be executed:

You can have both approaches enabled and execute some tasks directly in Kentico and other tasks via the external Windows service.

Scheduling reliability

Task execution by the Kentico application runs within the ASP.NET process, so tasks cannot be executed if the web application is not running. The application stops running when the process is recycled without being started again (after a long period of website inactivity).

If you want to run the scheduling reliably, we recommend using the Windows scheduling service.

To achieve reliable task execution without using the Windows scheduling service, you need to ensure that your website is always running. For example, you can prepare a utility or service that requests the home of your website on a regular basis.

Configuring execution by the Kentico application

By default, all scheduled tasks are executed by the Kentico application.

Setting the task execution time

There are two levels of settings that determine when the system executes tasks:

  • Task interval - the properties of individual scheduled tasks determine when tasks are ready for execution.
  • Application scheduler interval -determines the time interval after which the application checks if any tasks are ready to be executed.

Task interval

To configure the interval that determines when individual scheduled tasks are ready to be executed:

  1. Open the Scheduled tasks application.
  2. Edit () the scheduled task.
  3. Set the task’s scheduling options (Period, Start time, Every, Between, Days).
  4. Click Save.

Application scheduler interval

To configure how frequently the application checks if there are any tasks ready to be executed:

  1. Open the Settings application.
  2. Select the System category.
  3. Type a number of seconds into the Application scheduler interval setting.
  4. Click Save.

Execution of scheduled tasks by the Kentico application has two modes.

Request-based scheduler mode

This is the default mode. The application performs checks at the end of each standard page request. This means that tasks are only executed when user activity on your website generates requests.

In this case, the Application scheduler interval sets the minimum time between the checks:

  • For example, a value of 60 means that the application checks after 60 seconds even if multiple page requests occur per minute. Tasks are NOT executed if there are no page requests.
  • 0 disables the execution of tasks by the application.

****** Automatic scheduler mode**

You can configure the scheduler to process tasks regularly according to an automatic internal timer, regardless of website activity. To enable this mode, add the CMSUseAutomaticScheduler key into the /configuration/appSettings section of your web.config file:




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


In this case, the Application scheduler interval sets the precise interval between the checks:

  • Values between 1 - 30 seconds define the interval between checks. For example, a value of 30 means that the application checks tasks every 30 seconds.
  • 0 disables the execution of tasks by the application.

Configuring execution by the Windows service

Executing tasks using the external Windows service is recommended for resource‑consuming tasks, because the execution does not affect the performance of the Kentico application.

Enabling the Windows scheduler service

Prerequisites

You need to have the Kentico Scheduler Windows service installed and running.

Note

Only some of the default scheduled tasks support this option. The tasks that do not have the option available in the editing interface must be processed by the application itself.

  1. Open the Settings application.

  2. Select the System category.

  3. Enable the Use external service setting.

  4. In the Scheduled tasks application, enable the Use external service option for individual tasks.

    • Tasks with the Use external service option disabled will be executed by the Kentico application itself.
    • If the Use external service setting in the Settings application is disabled, even tasks with the Use external service option enabled are processed by the Kentico application itself.

Resolving context macros when executing tasks by the Windows service

Tasks that are executed by the Windows service cannot resolve macros dependent on application context (for example {% ApplicationPath %}). The context is not available when tasks are executed outside the application. Therefore, you cannot execute such tasks using the Windows service.

Setting the task execution time

There are two levels of settings that determine when the Windows scheduler service executes tasks:

  • Task interval - the properties of individual scheduled tasks determine when tasks are ready for execution.
  • Service scheduler interval - determines the time interval after which the service checks if any tasks are ready to be executed.

Task interval

To configure the interval that determines when individual scheduled tasks are ready to be executed:

  1. Open the Scheduled tasks application.
  2. Edit () the scheduled task.
  3. Set the task’s scheduling options (Period, Start time, Every, Between, Days).
  4. Click Save.

Service scheduler interval

To configure how frequently the Windows scheduler service checks if there are any tasks ready to be executed:

  1. Open the Settings application.
  2. Select the System category.
  3. Type a number of seconds into the Service scheduler interval setting.
  4. Click Save.
This setting only applies to tasks that are configured to be executed by the Windows service, not by the application itself.

The Service scheduler interval sets the precise interval between the checks:

  • Values between 1 - 30 seconds define the interval between checks.
    • For example, a value 30 means, that the service checks tasks every 30 seconds.
  • 0 disables the execution of tasks by the external service.

Additional low-level settings

Additional low-level scheduled task settings can be done by adding the keys listed in the Scheduler settings section of the Web.config application keys reference.