protected function execute(InputInterface $input, OutputInterface $output) { $lock = new LockHandler($this->getName()); if (!$lock->lock()) { $output->writeln('The command is already running in another process.'); return 0; } $repositoryName = $input->getArgument('repository'); if ($repositoryName) { $repository = $this->repositoryStorage->get($repositoryName); if ($repository === null) { throw new \InvalidArgumentException('Unknown repository ' . $repositoryName); } $repositories = [$repository]; } else { $repositories = $this->getRepositoriesToUpdate(); } foreach ($repositories as $repository) { $output->writeln(sprintf('Updating <info>%s</info>', $repository->getName())); $timer = microtime(true); $this->update($repository, $output); $output->writeln(sprintf('Took %ds', microtime(true) - $timer)); } $lock->release(); return 0; }
public function getStatistics($user, $repository) { $id = $user . '/' . $repository; $statistics = $this->cache->get($id); if (!$statistics instanceof Statistics) { $statistics = $this->wrapped->getStatistics($user, $repository); $this->cache->set($id, $statistics); } return $statistics; }
public function getStatistics($user, $repository) { // Fetch first, so that if an exception happens, we don't store the repository $statistics = $this->wrapped->getStatistics($user, $repository); // Store it $id = $user . '/' . $repository; if (!$this->repositories->get($id)) { $this->repositories->set($id, new Repository($id)); } return $statistics; }
protected function execute(InputInterface $input, OutputInterface $output) { foreach ($this->repositories as $id => $repository) { /** @var Repository $repository */ $repository = $this->repositories->get($id); $slug = $repository->getName(); $output->writeln(sprintf('Caching statistics for <info>%s</info>', $slug)); list($user, $repo) = explode('/', $slug, 2); try { $this->statisticsProvider->getStatistics($user, $repo); } catch (\Exception $e) { $output->writeln(sprintf('<error>Error while fetching statistics for %s</error>', $slug)); $output->writeln(sprintf('<error>%s: %s</error>', get_class($e), $e->getMessage())); } } }