Provides a Drupal queue you can use to process a bunch of operations in an asynchronous way.
For example if you have 1 million items you want to query and do operations on, in an update hook, it would be better to do them async.
Just use this queue, and pass it a callback and some arguments, and you are good to go.
Example
/**
* Update all of the nodes on the site.
*/
function mymodule_update_8001() {
$nids = somehow_get_an_array_of_one_million_nids();
$queue = \Drupal::queue('update_worker');
foreach ($nids as $nid) {
$queue->createItem([
'callback' => 'mymodule_update_node',
'arguments' => [
$nid,
],
]);
}
}
And then you probably have something like this defined in your module:
/**
* Helper function to update a node.
*/
function mymodule_update_node($nid) {
$node = Node::load($nid);
$node->set('my_field', 'some_new_value');
$node->save();
}
Now, instead of your site being offline while the update hook is running, you can just process all of the nodes asynchronously.
Of course, you could combine this into one more abstraction layer, by using the update hook to create for example 1000 queue items that would in turn each queue 1000 nids, meaning even less time spent running database updates. But that would be an exercise left to the reader.
Project information
Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Developer tools, Performance
56 sites report using this module
- Created by eiriksm on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
