Last active
November 28, 2016 18:17
-
-
Save jerbob92/10fd005bb9d469d54219 to your computer and use it in GitHub Desktop.
QueueWorker in Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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