Skip to content

Instantly share code, notes, and snippets.

@jerbob92
Last active November 28, 2016 18:17
Show Gist options
  • Save jerbob92/10fd005bb9d469d54219 to your computer and use it in GitHub Desktop.
Save jerbob92/10fd005bb9d469d54219 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