Sitefinity Schedule Task
sitefinity | .NET, CMS, Sitefinity | 2020-09-20
sitefinity | .NET, CMS, Sitefinity | 2020-09-20
Scheduled tasks in Sitefinity CMS are objects that can execute a predefined set of operation at a particular point in time.
You can use scheduled task… (read from reference..)
There are two important method,
Then we rewrite the code:
#SampleTask.cs
public class SampleTask : ScheduledTask
{
public SampleTask() { this.Key = "MyKey"; }
public override string TaskName { get { return this.GetType().FullName; } }
public override void ExecuteTask()
{
// Code to Execute Task
ScheduleTask();
}
public static void ScheduleTask()
{
SchedulingManager schedulingManager = SchedulingManager.GetManager();
var executeTime = DateTime.Now.AddMinutes(5);
var existingTask = schedulingManager.GetTaskData().FirstOrDefault(x => x.Key == this.Key);
if (existingTask == null)
{
// Create a new scheduled task
SampleTask newTask = new SampleTask()
{
ExecuteTime = executeTime
};
schedulingManager.AddTask(newTask);
}
else
{
existingTask.ExecuteTime = executeTime;
}
SchedulingManager.RescheduleNextRun();
schedulingManager.SaveChanges();
}
}
#Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
}
private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
{
HousekeepingTask.ScheduleTask(init: true, rescheduleNewTask: false);
InterfaceTask.ScheduleTask(init: true, rescheduleNewTask: false);
}
dbo.sf_scheduled_tasks
Columns |
---|
task_name |
ky |
is_running |
execute_time |
schedule_data |
Then we try to put debug point at ScheduleTask() method and got conclusion below.
Steps
Then check ScheduleTask() method,
Findings:
Then we got the conclusion on the columns as below:
Columns | Description |
---|---|
task_name | Name of class where implement the abstract class ScheduledTask |
ky | Task key |
is_running | True when task is running; False when task has yet to run |
execute_time | Task scheduled timing (next run) |
schedule_data | To store cron task config (not applicable in this investigate) |