Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Update worker

Security covered Maintenance fixes only 119 sites

This module provides a Drupal queue for processing a large number of operations asynchronously. It's useful for tasks like updating many database records without taking your site offline during the process. You can set up a callback function and pass it arguments to process items in the queue.

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.

Drupal 8–11

Ask your assistant about Update worker

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jun 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Slowing

Releases

Version Type Core PHP Release date
2.0.2 Stable 8–11 Mar 25, 2024
2.0.1 Stable 8–10 Jun 14, 2023