UPDATE: Winter '16 made huge improvements since I wrote this question after Spring '15. Most notably, the various methods on the FlexQueue object (and related methods on Test object)
My question as it was originally written:
I looked forward to the Apex Flex Queue that became GA with Spring '15. However, in actually trying to use it, I'm baffled as to how this is useful in its current implementation:
- How do I reorder the queue via API or Apex? It looks like the only option is via the Setup UI -- and I can't prioritize any 'Holding' jobs without aborting another one in the Queued state. See: http://screencast.com/t/uOAfg4Z73
- Again, referencing the screen shot above, this UI is not helpful to anyone without the Job ID being visible -- Our application enqueues background workers via a common class (SupremeQueryBatchableWrapper) so they are indistinguishable from one another
- Why does it throw a LimitException if you exceed the 100 slots? This type of exception can't be rescued in Apex so instead, you need to have code similar to (see related question: Apex Batch job limits not clear Queued vs Scheduled) this:
Integer enqueuedJobs = [SELECT COUNT() FROM AsyncApexJob WHERE JobType='BatchApex' AND Status IN ('Processing','Preparing','Queued','Holding')];
if(enqueuedJobs >= 5){
throw new TooManyBatchApexJobsException();
}
Am I overlooking something here? I can probably deal with the third bullet point (since we already have that code written). But the first two are head-scratchers