I have tried to find its answer on multiple places but unable to do so, I know Batch classes use Flex queues and Batch queues. Just wondering what does queueable interface or class use? Does it also use flex queues and batch queues or it uses some other queue?
3 Answers
The Flex Queue is its own unique queue, separate from the asynchronous queue. Basically, until a Batchable process starts, it is in the Flex Queue, and can have its priority changed. Once the system has resources, it starts building up jobs to perform in the asynchronous queue. This includes start, execute, and finish methods of Schedulable, Queueable, and Batchable, as well as future methods. I can't find an official Salesforce page with this image, but several blog posts show this depiction of asynchronous processing:
If anyone can source the appropriate Salesforce page this came from, please feel free to edit this answer.
As you can see, Bulk API, Batch, future (etc) all are in a per-org queue, and they are interleaved. There's a special rule that says that if there are more than 12 asynchronous calls from a single org, another org will get a chance to execute[citation needed]. It appears this may have changed, as the current documentation for @future says:
Avoid adding large numbers of future methods to the asynchronous queue, if possible. If more than 2,000 unprocessed requests from a single organization are in the queue, any additional requests from the same organization will be delayed while the queue handles requests from other organizations.
There's no such thing as different queues for different types of asynchronous processes. Salesforce considers each of these asynchronous calls equally, with some minor caveats (namely, one one Batchable start method may execute at a time per org). There is the Flex queue, and the asynchronous queue, which are two distinct queues in the system.
Generally speaking, asynchronous calls are processed in the order they are received, but if an org has too many items in the asynchronous queue, the queue may be reordered. Also, chaining requests (e.g. Queueable calling Queueable) will impose a minimum delay between executions to give other orgs a chance to execute.
-
Thank you so much for the help. So if I got that right the concept of flex queue comes only in case of batch class for the pending/on hold jobs and once the jobs are ready to be processed, they go in asynchronous queue. On the other hand, Queueable and future Method job always go to Asynchronous queue, there is no intermediate queue for them, where the pending jobs are stored?– StudentCommented Aug 21, 2019 at 18:34
-
Batch jobs and Queueable are part of the flex queue, future jobs are not. See the example given on the "FlexQueue Class" page. Commented Jun 1, 2021 at 13:52
-
1@FelixvanHove That's incorrect (a documentation bug). Queueables are not part of the flex queue. If that were true, you would be limited to 100 Queueable + Batchable.– sfdcfox ♦Commented Jun 1, 2021 at 14:42
-
@sfdcfox, you were right and Salesforce's documentation has been corrected. Commented Aug 9, 2021 at 9:21
-
@sfdcfox, just for clarification of a helpful post - "The Flex Queue is its own unique queue, separate from the asynchronous queue" and "There's no such thing as different queues for different types of processes" seem confusing - any chance that could be parsed out a bit for ease of understanding?– number41Commented Jan 10, 2022 at 8:14
I just got confirmation from Salesforce support on this. When Batchables are added they have a state of Holding at first. Queueables do not and therefore can't count against the limit of 100 in Holding. (They start in Queued.)
If you manage your Batchables instance-wide you won't get that exception no matter how many Queueables you add. Oddly there isn't a governor limit on queueable count at all. There is a limit of 2000 unexecuted futures but that doesn't apply to queueables.
See also this thread.
As per my experience the flex queue is the place where all the queued job stay. It keeps there till the time of any free resource found . Also the job queue can hold 100 after that count all the jobs send for the flex queue.
-
ok that's the contradictory information, I am a bit confused now. Do you have any article that you could share?– StudentCommented Aug 21, 2019 at 19:44