|
||
You can write custom tasks to be executed by web farm servers. This is done by adding the code of your tasks into the App_Code folder of your web project (or Old_App_Code if you installed Kentico CMS as a web application).
The following example shows how to create a custom synchronization task that logs information events into the event log of all servers in the web farm:
1. Open your web project in Visual Studio, expand the App_Code folder and add a new class into it called WebFarmTaskLoader.cs.
2. Add the following references:
[C#]
using CMS.SettingsProvider; |
3. Delete the default class declaration and its content. Instead extend the CMSModuleLoader partial class and define a new attribute for it as shown below:
[C#]
[WebFarmTaskLoader] public partial class CMSModuleLoader { /// <summary> /// Module registration /// </summary> private class WebFarmTaskLoaderAttribute : CMSLoaderAttribute { ... } } |
4. Enter the following code into the WebFarmTaskLoaderAttribute class:
[C#]
/// <summary> |
The override of the Init() method is called automatically when the application starts. The code assigns a handler for the OnProcessCustomTask event, which is then used to log a record with Execute as its event code into the website's event log.
5. Repeat the steps above for all web servers in the web farm, so that the Execute event is logged for each one. Build their projects if they are installed as a web application.
6. Select one web farm server and expand the Init() method according to the following:
[C#]
/// <summary> |
This ensures that the custom task is created when the selected server is started and if successful, an event with Create as its event code will be logged for the given server.
7. Finally, save the changes (Build the project if you installed it as a web application). You can see the results by checking the event log for all web farm servers at Site Manager -> Administration -> Event log.