public static function makeQueueManager(Backend $backend)
 {
     $settings = self::getSettings();
     $lock = self::makeLock($backend);
     $manager = new Manager($backend, $lock);
     $manager->setNumberOfAvailableQueues($settings->numQueueWorkers->getValue());
     $manager->setNumberOfRequestsToProcessAtSameTime($settings->numRequestsToProcess->getValue());
     return $manager;
 }
 private function processQueue(Queue\Manager $queueManager)
 {
     Common::printDebug('We are going to process the queue');
     set_time_limit(0);
     try {
         $processor = new Processor($queueManager);
         $processor->process();
     } catch (Exception $e) {
         Common::printDebug('Failed to process queue: ' . $e->getMessage());
         // TODO how could we report errors better as the response is already sent? also monitoring ...
     }
     $queueManager->unlock();
 }
 /**
  * @param RequestSet $requestSet
  * @return bool true if we still have the lock and if expire was set successfully
  */
 private function extendLockExpireToMakeSureWeCanProcessARequestSet(RequestSet $requestSet)
 {
     // 2 seconds per tracking request should give it enough time to process it
     $ttl = $requestSet->getNumberOfRequests() * 2;
     $ttl = max($ttl, 20);
     // lock for at least 20 seconds
     return $this->queueManager->expireLock($ttl);
 }
 public function test_process_ShouldNotDirectlyProcessQueue_IfAlreadyLocked()
 {
     Queue\Factory::getSettings()->numQueueWorkers->setValue(1);
     $this->handler->enableProcessingInTrackerMode();
     $this->queue->setNumberOfRequestsToProcessAtSameTime(1);
     // there is only one worker, so make sure that queue is locked
     $lock = new Queue\Lock($this->backend);
     $lock->acquireLock(0);
     $this->assertSame(0, $this->queue->getNumberOfRequestSetsInAllQueues());
     $this->processDummyRequests();
     $this->assertSame(1, $this->queue->getNumberOfRequestSetsInAllQueues());
     $this->processDummyRequests();
     $this->assertSame(2, $this->queue->getNumberOfRequestSetsInAllQueues());
     $this->queue->unlock();
 }
 public function getQueueIdForVisitor($visitorId)
 {
     return parent::getQueueIdForVisitor($visitorId);
 }
 private function addRequestSetsToQueue($numRequestSets)
 {
     for ($index = 1; $index <= $numRequestSets; $index++) {
         $this->queue->addRequestSetToQueues($this->buildRequestSet(1));
     }
 }