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 won’t 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 that the Kentico application’s worker process remains 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 don’t 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 also use the Scheduler Windows service if you want to process scheduled tasks independently on the Kentico application.

Processing scheduled tasks on MVC sites in regular intervals

To guarantee that smart search tasks are processed in regular intervals even if the Kentico application isn’t running, set up processing of the Execute search tasks scheduled task using the Windows scheduler service.

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: Processing smart search tasks on MVC sites in regular intervals

You need to duplicate the Execute search tasks scheduled task, which the system contains by default, but isn’t runnable by an external scheduler:

  1. Install the Scheduler Windows service.

  2. Go to Settings (application) -> System -> Scheduler and enable Use external service.

  3. Open the Scheduled tasks application and click New task.

  4. Set the following properties of the new task:

    • Assembly name - CMS.Scheduler
    • Class - CMS.Scheduler.SearchTaskExecutor
    • Period - set the desired time interval. For example, the original ‘Execute search tasks’ scheduled task, available in the system by default, uses a 4 hour interval.
    • Use external service - enabled
  5. Click Save.

  6. Edit the original Execute search tasks scheduled task.

  7. Disable the Task enabled option.

  8. Click Save.

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