Hi,
In your job you can verify if any job is currently running by calling static method ScheduledJob.ListRunningJobs (http://sdk.episerver.com/library/cms6/html/M_EPiServer_DataAbstraction_ScheduledJob_ListRunningJobs.htm)
Something is not working for me. Consider this code:
public static string Execute()
{
var startTime = DateTime.Now.ToString();
var jobs = ScheduledJob.ListRunningJobs();
Thread.Sleep(100000);
var endTime = DateTime.Now.ToString();
return string.Format("start: {0}, end: {1}, jobcount: {2}", startTime, endTime, jobs.Count);
}
And an output I get on job's history tab:
7/24/2012 1:47:58 PM OK start: 7/24/2012 1:46:18 PM, end: 7/24/2012 1:47:58 PM, jobcount: 0
7/24/2012 1:47:48 PM OK start: 7/24/2012 1:46:08 PM, end: 7/24/2012 1:47:48 PM, jobcount: 0
Any idea why I always get an empty list?
Ok, it seems you are using an “old” approach with the static Execute method. The ListRunningJobs() method returns only jobs implemented with new approach. Your job class should inherit from EPiServer.BaseLibrary.Scheduling.JobBase and override Execute method.
You can find more details here: http://thisisnothing.wordpress.com/2010/05/13/scheduled-jobs-in-episerver-cms-6/
Now it seems to be impossible to run more than one job at the same time. I am fine with this behaviour as long as it is guaranteed, but is it? In particular in multi-server scenarios? Or do I still need to check with ScheduledJob.ListRunningJobs()?
It is guaranteed that only one instance of a certain job type is executed at the same time. You don't need to call ListRunningJobs() for this. However several instances of different job types can run in parallel.
What is the suggested way to ensure that only one EPiServer job is run at any given time? Is there any built-in mechanism for that?