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:
- Enable the scheduler for your live site application.
- 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:
Open your live site project in Visual Studio.
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(); ... }
Open your live site project in Visual Studio.
Edit your application’s startup class (Startup.cs by default).
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:
Open the Scheduled tasks application.
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:
- Switch to the (global) task listing.
- Expand the Other actions (…) menu next to the given task.
- Select Clone.
- Adjust the task’s display and code names as required.
- Click Show advanced settings.
- Select your site in the Clone to site field.
- Click Clone.You can now configure the new site-specific task to run on the live site.
Create a New task or edit an existing one.
Switch the Run task on option to Live site.
Adjust the task properties as required.
Click Save.
The task will now be executed by your live site application.