Created
April 4, 2019 13:45
-
-
Save mattschaff/6b5938ed44e83d1c74f19abeb90c85ef to your computer and use it in GitHub Desktop.
Drupal 8: Custom queue worker processed by cron
This file contains hidden or 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\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