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
31 * Constructs a queue factory.
33 public function __construct(Settings $settings) {
34 $this->settings = $settings;
38 * Constructs a new queue.
41 * The name of the queue to work with.
42 * @param bool $reliable
43 * (optional) TRUE if the ordering of items and guaranteeing every item executes at
44 * least once is important, FALSE if scalability is the main concern. Defaults
47 * @return \Drupal\Core\Queue\QueueInterface
48 * A queue implementation for the given name.
50 public function get($name, $reliable = FALSE) {
51 if (!isset($this->queues[$name])) {
52 // If it is a reliable queue, check the specific settings first.
54 $service_name = $this->settings->get('queue_reliable_service_' . $name);
56 // If no reliable queue was defined, check the service and global
57 // settings, fall back to queue.database.
58 if (empty($service_name)) {
59 $service_name = $this->settings->get('queue_service_' . $name, $this->settings->get('queue_default', 'queue.database'));
61 $this->queues[$name] = $this->container->get($service_name)->get($name);
63 return $this->queues[$name];