Processing scheduled tasks on the live site

Most default scheduled tasks are intended to be processed by the Xperience administration application. The tasks typically manage or update data in the shared database, so running on the administration application is sufficient. Executing tasks via the administration also has the advantage that any performance requirements are offloaded from your live site application.

However, the system also allows you to schedule site-specific tasks that are executed by the live site application. For example, you can use this option if you wish to create a custom task that works with the application memory or the local file system.

To run scheduled tasks on the live site:

  1. Enable the scheduler for your live site application.
  2. Configure individual tasks to run on the live site.

Enabling the scheduler on the live site

Developers need to enable the scheduler on the side of the live site application:

  1. Open your live site project in Visual Studio.

  2. Enable the scheduler feature by calling the UseScheduler method of the ApplicationBuilder instance.

    • Enable the feature at the start of your application’s life cycle, for example in the Application_Start method of your project’s Global.asax file.

      MVC projects created by the installer contain the ApplicationConfig class, whose RegisterFeatures method is called in the Application_Start method by default. You can use this class to encapsulate all of your ApplicationBuilder code (enabling and configuring of Xperience MVC features).

      
      
      
        using Kentico.Web.Mvc;
      
        ...
      
        protected void Application_Start()
        {
            ...
      
            // Gets the ApplicationBuilder instance
            // Allows you to enable and configure selected Xperience MVC integration features
            ApplicationBuilder builder = ApplicationBuilder.Current;
      
            // Enables the scheduler feature, which starts the automatic scheduler
            builder.UseScheduler();
      
            ...
        }
      
      
        
  1. Open your live site project in Visual Studio.

  2. Edit your application’s startup class (Startup.cs by default).

  3. Enable the scheduler feature by calling the UseScheduler method of the IFeaturesBuilder delegate passed to the IServiceCollection.AddKentico method within ConfigureServices.

    
    
    
    using Kentico.Web.Mvc;
    
    ...
    
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        // Enables and configures Xperience features
        services.AddKentico(features =>
        {
            // Enables the scheduler feature, which starts the automatic scheduler
            features.UseScheduler();
            ... 
        });
    
        ...
    }
    
    
    

Enabling the UseScheduler feature starts the automatic scheduler. The scheduler then sends requests to the ~/CMSPages/Scheduler.ashx system route, based on the interval configured in the settings. The requests ensure processing of scheduled tasks that are ready to run.

You can now configure individual tasks to run on the live site.

Configuring tasks to run on the live site

After enabling the scheduler feature for your live site application, you can configure site-specific scheduled tasks to be executed on the live site:

  1. Open the Scheduled tasks application.

  2. Select the appropriate Site.

    Global tasks

    Global tasks are always processed by the administration application. If you wish to run a global task on the live site, you need to create a separate copy:

    1. Switch to the (global) task listing.
    2. Expand the Other actions () menu next to the given task.
    3. Select Clone.
    4. Adjust the task’s display and code names as required.
    5. Click Show advanced settings.
    6. Select your site in the Clone to site field.
    7. Click Clone.You can now configure the new site-specific task to run on the live site.
  3. Create a New task or edit an existing one.

  4. Switch the Run task on option to Live site.

  5. Adjust the task properties as required.

  6. Click Save.

The task will now be executed by your live site application.