I have tested the new Summer '13 System.scheduleBatch
method in a DE org and am wondering if I have misunderstood its usage. My principle reason was because I wanted to know if it would allow me to run more than 5 Batch jobs concurrently (wishful thinking) but secondary that it would queue them up successfully, so I built my test:
System.scheduleBatch( new AccountBatchJob(), 'test1', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test2', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test3', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test4', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test5', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test6', 0, 1);
5 jobs ran concurrently, which is what I expected tbh. I was expecting that since I didn't have resources, test6 would remain queued. Not so, it disappeared into the ether!
So, I figured that it must have got confused because I had all 6 to start immediately so I changed my test to:
System.scheduleBatch( new AccountBatchJob(), 'test1', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test2', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test3', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test4', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test5', 0, 1);
System.scheduleBatch( new AccountBatchJob(), 'test6', 1, 1);
Again, 5 run concurrently and nicely queues test6 in Schedule Jobs to start in one minute. I expected that in 1 minute, test6 still wouldn't have resources and would wait nicely until there were as the release notes state:
• When you call
Database.scheduleBatch,
Salesforce schedules the job for execution at the specified time. Actual execution might be delayed based on service availability.
Since my service availability would have been 0, this implies that it would have waited until such a time that there was a slot free. However, it's been 30 minutes now and still no dice.
This being the case, I'm struggling to see a valid use case for this function (it's certainly not what I hoped it would be).
My question is, has anyone successfully managed to get this function to queue batch jobs so that when resources are not available it waits until they are? If so, what have I missed?
Thanks
Update: Salesforce support are telling me that the 6th job did actually run, but gave a limits exception because 5 other jobs are still running. They've asked me to reproduce in another org so I've just finished that to witness the same behaviour. I'm just really waiting for them to tell me what I already know.
Update 2: Eventually got to speak to backline support who tell me that the purpose of System.scheduleBatch
was to remove a layer of complexity so that devs don't have to create an intermediary class that implements Schedulable
and then calls Database.executeBatch
. However, as I explained to him, that renders System.scheduleBatch
completely useless because without the intermediary class, you can't check if there are enough batch slots free. He's escalating internally.
minutesFromNow
parameter. The docs say 'This argument must be greater than zero'. Perhaps they are defaulting to 1 behind the scenes? In which case all 6 jobs run at the 1 minute mark and hit the limit.