QueueWorkerManager.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\Queue;
  3. use Drupal\Core\Cache\CacheBackendInterface;
  4. use Drupal\Core\Extension\ModuleHandlerInterface;
  5. use Drupal\Core\Plugin\DefaultPluginManager;
  6. /**
  7. * Defines the queue worker manager.
  8. *
  9. * @see \Drupal\Core\Queue\QueueWorkerInterface
  10. * @see \Drupal\Core\Queue\QueueWorkerBase
  11. * @see \Drupal\Core\Annotation\QueueWorker
  12. * @see plugin_api
  13. */
  14. class QueueWorkerManager extends DefaultPluginManager implements QueueWorkerManagerInterface {
  15. /**
  16. * Constructs an QueueWorkerManager object.
  17. *
  18. * @param \Traversable $namespaces
  19. * An object that implements \Traversable which contains the root paths
  20. * keyed by the corresponding namespace to look for plugin implementations.
  21. * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
  22. * Cache backend instance to use.
  23. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
  24. * The module handler.
  25. */
  26. public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
  27. parent::__construct('Plugin/QueueWorker', $namespaces, $module_handler, 'Drupal\Core\Queue\QueueWorkerInterface', 'Drupal\Core\Annotation\QueueWorker');
  28. $this->setCacheBackend($cache_backend, 'queue_plugins');
  29. $this->alterInfo('queue_info');
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function processDefinition(&$definition, $plugin_id) {
  35. parent::processDefinition($definition, $plugin_id);
  36. // Assign a default time if a cron is specified.
  37. if (isset($definition['cron'])) {
  38. $definition['cron'] += [
  39. 'time' => 15,
  40. ];
  41. }
  42. }
  43. /**
  44. * {@inheritdoc}
  45. *
  46. * @return \Drupal\Core\Queue\QueueWorkerInterface
  47. */
  48. public function createInstance($plugin_id, array $configuration = []) {
  49. return parent::createInstance($plugin_id, $configuration);
  50. }
  51. }