3 namespace Drupal\Core\Queue;
5 use Drupal\Core\Site\Settings;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
10 * Defines the queue factory.
12 class QueueFactory implements ContainerAwareInterface {
14 use ContainerAwareTrait;
17 * Instantiated queues, keyed by name.
21 protected $queues = [];
24 * The settings object.
26 * @var \Drupal\Core\Site\Settings
32 * Constructs a queue factory.
34 public function __construct(Settings $settings) {
35 $this->settings = $settings;
39 * Constructs a new queue.
42 * The name of the queue to work with.
43 * @param bool $reliable
44 * (optional) TRUE if the ordering of items and guaranteeing every item executes at
45 * least once is important, FALSE if scalability is the main concern. Defaults
48 * @return \Drupal\Core\Queue\QueueInterface
49 * A queue implementation for the given name.
51 public function get($name, $reliable = FALSE) {
52 if (!isset($this->queues[$name])) {
53 // If it is a reliable queue, check the specific settings first.
55 $service_name = $this->settings->get('queue_reliable_service_' . $name);
57 // If no reliable queue was defined, check the service and global
58 // settings, fall back to queue.database.
59 if (empty($service_name)) {
60 $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
62 $this->queues[$name] = $this->container->get($service_name)->get($name);
64 return $this->queues[$name];