Processing scheduled tasks when developing MVC applications

When using a separate MVC application together with a Kentico application, you need to ensure that scheduled tasks on the Kentico application get processed in regular intervals. As the Kentico application itself does not usually receive traffic from site visitors, you either need to keep the application alive in a different way or process the tasks independently on the Kentico application’s worker process.

You can use one of the following approaches for processing scheduled tasks when developing MVC applications:

  • Automatic scheduler mode – recommended approach. Requires the Kentico application’s worker process to remain alive.
  • Scheduler Windows service – independent of the Kentico application’s worker process.

Automatic scheduler mode

  1. Configure the Kentico application to use Automatic scheduler mode.

  2. Set the Idle Time-out (minutes) setting of your IIS application pool to 0. Otherwise, the application pool worker process shuts down after a period of inactivity. As the Kentico application does not receive traffic from visitors, the worker process would shut down if no one used the Kentico administration for a certain period of time and scheduled tasks would not get executed.

    • If you do not want to set the Idle Time-out (minutes) setting to 0, you can keep the worker process alive by sending requests to the Kentico application within the set interval.

Scheduler Windows service

You can use the Scheduler Windows service if you want to process scheduled tasks independently on the Kentico application.

Note:

  • The Windows scheduler service requires the Kentico EMS license.
  • Tasks that are processed by the Windows service cannot resolve macros dependent on application context, such as: {% ApplicationPath %}.

Example - Regularly processing search indexing tasks on MVC sites

To use the scheduler to regularly process search indexing tasks, configure the appropriate scheduled tasks to run using the Scheduler Windows service.

As a prerequisite, you need to:

  1. Install the Scheduler Windows service.
  2. Open the Settings application in Kentico.
  3. Expand the System category and enable the Use external service setting.
  4. Click Save.
  1. Open the Scheduled tasks application.
  2. Edit the Execute Azure search tasks item (for Azure Search indexes).
  3. Enable the Use external service property.
  4. Click Save.
  5. Repeat the same steps for the Execute local search tasks scheduled task (for locally stored search indexes).

The system now processes search tasks generated by both the MVC and Kentico application using the Windows scheduler service.