Skip to content

Instantly share code, notes, and snippets.

@mattschaff
Created April 4, 2019 13:45
Show Gist options
  • Save mattschaff/6b5938ed44e83d1c74f19abeb90c85ef to your computer and use it in GitHub Desktop.
Save mattschaff/6b5938ed44e83d1c74f19abeb90c85ef to your computer and use it in GitHub Desktop.
Drupal 8: Custom queue worker processed by cron
<?php
/**
* @file
* Contains \Drupal\my_module\Plugin\QueueWorker\MyModuleQueueEvent.
*/
namespace Drupal\my_module\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
/**
* Queue worker that processes a My Module queue item
*
* @QueueWorker(
* id = "my_module_queue_worker",
* title = "My Module Queue Worker",
* cron = {"time" = 10}
* )
* ^ "time" is the max execution time of this worker when run by cron
*/
class MyModuleQueueEvent extends QueueWorkerBase {
/**
*
* Processes a single item of Queue.
*
* @param mixed $data
* The data that was passed to
* \Drupal\Core\Queue\QueueInterface::createItem() when the item was queued.
*
*/
public function processItem($data) {
// Logic to process $data.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment