/** * @return Connection[] */ protected function decideClusters() { $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); if ($this->params['cluster'] !== null && !$this->canWriteToCluster($config, $this->params['cluster'])) { // Just in case a job is present in the queue but its cluster // has been removed from the config file. $cluster = $this->params['cluster']; LoggerFactory::getInstance('CirrusSearch')->warning("Received job {method} for unwritable cluster {cluster} {diff}s after insertion", array('method' => $this->params['method'], 'arguments' => $this->params['arguments'], 'diff' => time() - $this->params['createdAt'], 'cluster' => $cluster)); // this job does not allow retries so we just need to throw an exception throw new \RuntimeException("Received job for unwritable cluster {$cluster}."); } if ($this->params['cluster'] !== null) { // parent::__construct initialized the correct connection $name = $this->connection->getClusterName(); return array($name => $this->connection); } if ($config->has('CirrusSearchWriteClusters')) { $clusters = $config->get('CirrusSearchWriteClusters'); if (is_null($clusters)) { $clusters = array_keys($config->get('CirrusSearchClusters')); } } else { $clusters = array_keys($config->get('CirrusSearchClusters')); } $connections = array(); foreach ($clusters as $name) { $connections[$name] = Connection::getPool($config, $name); } return $connections; }
public function getConnection() { if ($this->connection === null) { $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); $cluster = $this->decideCluster($config); $this->connection = Connection::getPool($config, $cluster); } return $this->connection; }
protected function decideClusters() { $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); if ($this->params['cluster'] !== null) { // parent::__construct initialized the correct connection $name = $this->connection->getClusterName(); return array($name => $this->connection); } $clusters = $config->get('CirrusSearchClusters'); $connections = array(); foreach (array_keys($clusters) as $name) { $connections[$name] = Connection::getPool($config, $name); } return $connections; }
public function getConnection($cluster = null) { if ($cluster) { $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); if (!$config->getElement('CirrusSearchClusters', $cluster)) { $this->error('Unknown cluster.', 1); } return Connection::getPool($config, $cluster); } if ($this->connection === null) { $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); $cluster = $this->decideCluster($config); $this->connection = Connection::getPool($config, $cluster); } return $this->connection; }
public function __construct($title, $params) { $params += array('cluster' => null); // eg: DeletePages -> cirrusSearchDeletePages $jobName = 'cirrusSearch' . str_replace('CirrusSearch\\Job\\', '', get_class($this)); parent::__construct($jobName, $title, $params); // All CirrusSearch jobs are reasonably expensive. Most involve parsing and it // is ok to remove duplicate _unclaimed_ cirrus jobs. Once a cirrus job is claimed // it can't be deduplicated or else the search index will end up with out of date // data. Luckily, this is how the JobQueue implementations work. $this->removeDuplicates = true; $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); // When the 'cluster' parameter is provided the job must only operate on // the specified cluster, take special care to ensure nested jobs get the // correct cluster set. When set to null all clusters should be written to. $this->connection = Connection::getPool($config, $params['cluster']); }