ensuring only one job instance

Vote:
 

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?

#60179
Jul 24, 2012 9:46
Vote:
 

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)

#60192
Jul 24, 2012 12:21
Vote:
 

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?

#60193
Jul 24, 2012 14:01
Vote:
 

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/

#60195
Jul 24, 2012 15:25
Vote:
 

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()?

#60198
Jul 24, 2012 16:05
Vote:
 

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.

#60199
Jul 24, 2012 17:19
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.