Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $systemCheck = new SystemCheck();
     $systemCheck->checkRedisIsInstalled();
     $trackerEnvironment = new Environment('tracker');
     $trackerEnvironment->init();
     Log::unsetInstance();
     $trackerEnvironment->getContainer()->get('Piwik\\Access')->setSuperUserAccess(false);
     $trackerEnvironment->getContainer()->get('Piwik\\Plugin\\Manager')->setTrackerPluginsNotToLoad(array('Provider'));
     Tracker::loadTrackerEnvironment();
     if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
         $GLOBALS['PIWIK_TRACKER_DEBUG'] = true;
     }
     $backend = Queue\Factory::makeBackend();
     $queueManager = Queue\Factory::makeQueueManager($backend);
     if (!$queueManager->canAcquireMoreLocks()) {
         $trackerEnvironment->destroy();
         $this->writeSuccessMessage($output, array("Nothing to proccess. Already max number of workers in process."));
         return;
     }
     $shouldProcess = false;
     foreach ($queueManager->getAllQueues() as $queue) {
         if ($queue->shouldProcess()) {
             $shouldProcess = true;
             break;
         }
     }
     if (!$shouldProcess) {
         $trackerEnvironment->destroy();
         $this->writeSuccessMessage($output, array("No queue currently needs processing"));
         return;
     }
     $output->writeln("<info>Starting to process request sets, this can take a while</info>");
     register_shutdown_function(function () use($queueManager) {
         $queueManager->unlock();
     });
     $startTime = microtime(true);
     $processor = new Processor($queueManager);
     $processor->setNumberOfMaxBatchesToProcess(1000);
     $tracker = $processor->process();
     $neededTime = microtime(true) - $startTime;
     $numRequestsTracked = $tracker->getCountOfLoggedRequests();
     $requestsPerSecond = $this->getNumberOfRequestsPerSecond($numRequestsTracked, $neededTime);
     Piwik::postEvent('Tracker.end');
     $trackerEnvironment->destroy();
     $this->writeSuccessMessage($output, array(sprintf('This worker finished queue processing with %sreq/s (%s requests in %02.2f seconds)', $requestsPerSecond, $numRequestsTracked, $neededTime)));
 }
Exemplo n.º 2
0
 public function destroyEnvironment()
 {
     if ($this->piwikEnvironment === null) {
         return;
     }
     $this->piwikEnvironment->destroy();
     $this->piwikEnvironment = null;
 }
Exemplo n.º 3
0
 public static function getSegmentsMetadata()
 {
     // Refresh cache for CustomVariables\Model
     Cache::clearCacheGeneral();
     $segments = array();
     $environment = new Environment(null);
     $exception = null;
     try {
         $environment->init();
         $environment->getContainer()->get('Piwik\\Plugin\\Manager')->loadActivatedPlugins();
         foreach (Dimension::getAllDimensions() as $dimension) {
             if ($dimension instanceof CustomVariableName || $dimension instanceof CustomVariableValue) {
                 continue;
                 // added manually below
             }
             foreach ($dimension->getSegments() as $segment) {
                 $segments[] = $segment->getSegment();
             }
         }
         // add CustomVariables manually since the data provider may not have access to the DB
         for ($i = 1; $i != Model::DEFAULT_CUSTOM_VAR_COUNT + 1; ++$i) {
             $segments = array_merge($segments, self::getCustomVariableSegments($i));
         }
         $segments = array_merge($segments, self::getCustomVariableSegments());
     } catch (\Exception $ex) {
         $exception = $ex;
         echo $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n";
     }
     $environment->destroy();
     if (!empty($exception)) {
         throw $exception;
     }
     return $segments;
 }