public function process(Tracker $tracker = null) { $tracker = $tracker ?: new Tracker(); if (!$tracker->shouldRecordStatistics()) { return $tracker; } $request = new RequestSet(); $request->rememberEnvironment(); $loops = 0; try { while ($queue = $this->queueManager->lockNext()) { if ($loops > $this->numMaxBatchesToProcess) { Common::printDebug('This worker processed ' . $loops . ' times, stopping now.'); break; } else { $loops++; } $queuedRequestSets = $queue->getRequestSetsToProcess(); if (!empty($queuedRequestSets)) { $requestSetsToRetry = $this->processRequestSets($tracker, $queuedRequestSets); $this->processRequestSets($tracker, $requestSetsToRetry); $queue->markRequestSetsAsProcessed(); // TODO if markR..() fails, we would process them again later } $this->queueManager->unlock(); } } catch (Exception $e) { Common::printDebug('Failed to process a request set: ' . $e->getMessage()); $this->queueManager->unlock(); $request->restoreEnvironment(); throw $e; } $request->restoreEnvironment(); return $tracker; }
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(); }
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(); }