Change record status: 
Project: 
Introduced in branch: 
11.5.x
Introduced in version: 
11.5.0
Description: 

Drupal core now includes an additional Drupal\Core\Queue\InstantQueueRunnerInterface service which can be used to execute queues at kernel terminate, after the request is sent.

This can be used where modules use queues as a response to saving entities and where possible would like queue items generated by user actions to be processed quicker than via scheduled cron runs. Examples could be sending notifications, search indexing, or invalidating cache tags in varnish or CDNs.

Injecting the queue runner, and then calling ::registerQueue() will add the queue to a list to be processed at the end of the request.

$this->instantQueueRunner->registerQueue($queue_name);

By default, a maximum of five items are processed per queue, this is controlled via the following service parameter which can be modified via a site-specific services.yml:

  instant_queue.config:
    maximumItems: 5

Note that there is no guarantee that the same items will be processed as the ones created on the page, this mechanism only increases the likelihood of items getting processed earlier.

Impacts: 
Module developers