Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save itmyprofession/4e88e907b9d86bc7bb4ba8da6e2e9715 to your computer and use it in GitHub Desktop.
Save itmyprofession/4e88e907b9d86bc7bb4ba8da6e2e9715 to your computer and use it in GitHub Desktop.
QueueWorker in Drupal 8
<?php
/**
* Implements hook_entity_update().
*/
function mymodule_entity_update($entity) {
$queue = \Drupal::queue('mymodule_tasks_entity_updates');
$data = [ 'entity_type' => $entity->getEntityType(), 'id' => $entity->id()];
$queue->createItem($data);
}
<?php
/**
* @file
* Contains \Drupal\mymodule\Plugin\QueueWorker\MyModuleTaskWorkerEntityUpdate.
*/
namespace Drupal\mymodule\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
/**
* Processes Tasks for My Module.
*
* @QueueWorker(
* id = "mymodule_tasks_entity_updates",
* title = @Translation("My Module Tasks Worker: Entity Updates"),
* cron = {"time" = 60}
* )
*/
class MyModuleTaskWorkerEntityUpdate extends QueueWorkerBase {
/**
* {@inheritdoc}
*/
public function processItem($data) {
// Process $data here.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment