From 47efbfecc4f260ab9b354ed859eb7edda660ebbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Thu, 30 Mar 2017 16:04:07 +0200 Subject: [PATCH] * cache refresh extended to jcat and streams --- config/autoload/cli.global.php | 4 ++-- ...acheCommand.php => UpdateCacheCommand.php} | 8 ++++--- ...tory.php => UpdateCacheCommandFactory.php} | 4 ++-- src/App/Service/CiExecutorService.php | 23 +++++-------------- 4 files changed, 15 insertions(+), 24 deletions(-) rename src/App/Command/{UpdateNightlyCacheCommand.php => UpdateCacheCommand.php} (69%) rename src/App/Command/{UpdateNightlyCacheCommandFactory.php => UpdateCacheCommandFactory.php} (74%) diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index d61301d..6346f73 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -4,12 +4,12 @@ return [ 'dependencies' => [ 'invokables' => [], 'factories' => [ - App\Command\UpdateNightlyCacheCommand::class => App\Command\UpdateNightlyCacheCommandFactory::class, + App\Command\UpdateCacheCommand::class => App\Command\UpdateCacheCommandFactory::class, ], ], 'console' => [ 'commands' => [ - App\Command\UpdateNightlyCacheCommand::class, + App\Command\UpdateCacheCommand::class, ], ], ]; diff --git a/src/App/Command/UpdateNightlyCacheCommand.php b/src/App/Command/UpdateCacheCommand.php similarity index 69% rename from src/App/Command/UpdateNightlyCacheCommand.php rename to src/App/Command/UpdateCacheCommand.php index acf064a..511787c 100644 --- a/src/App/Command/UpdateNightlyCacheCommand.php +++ b/src/App/Command/UpdateCacheCommand.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class UpdateNightlyCacheCommand extends Command +class UpdateCacheCommand extends Command { /** * @var CiExecutorService @@ -22,12 +22,14 @@ class UpdateNightlyCacheCommand extends Command protected function configure() { - $this->setName('nightly:update') - ->setDescription('Updates nightly configuration cache'); + $this->setName('cache:update') + ->setDescription('Updates cache of jcat packages, streams and active nightly ci configuration'); } protected function execute(InputInterface $input, OutputInterface $output) { $this->ciExecutorService->getActiveNightlyConfiguration(true); + $this->ciExecutorService->getCiStreams(false); + $this->ciExecutorService->getJcatPackages(false); } } diff --git a/src/App/Command/UpdateNightlyCacheCommandFactory.php b/src/App/Command/UpdateCacheCommandFactory.php similarity index 74% rename from src/App/Command/UpdateNightlyCacheCommandFactory.php rename to src/App/Command/UpdateCacheCommandFactory.php index fd1b5c7..75c60d8 100644 --- a/src/App/Command/UpdateNightlyCacheCommandFactory.php +++ b/src/App/Command/UpdateCacheCommandFactory.php @@ -5,12 +5,12 @@ namespace App\Command; use App\Service\CiExecutorService; use Interop\Container\ContainerInterface; -class UpdateNightlyCacheCommandFactory +class UpdateCacheCommandFactory { public function __invoke(ContainerInterface $container) { /** @var CiExecutorService $ciExecutorService */ $ciExecutorService = $container->get(CiExecutorService::class); - return new UpdateNightlyCacheCommand($ciExecutorService); + return new UpdateCacheCommand($ciExecutorService); } } diff --git a/src/App/Service/CiExecutorService.php b/src/App/Service/CiExecutorService.php index 8e9b8f2..c0a4c80 100644 --- a/src/App/Service/CiExecutorService.php +++ b/src/App/Service/CiExecutorService.php @@ -81,20 +81,14 @@ class CiExecutorService /** * Get available jcat versions from config2 page * - * @param bool $cached + * @param bool $forceReload * @return array */ - public function getJcatPackages($cached = true) + public function getJcatPackages(bool $forceReload = false) { - if (!$cached) { - $config2Html = $this->getConfig2Html(); - $staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE"); - return $this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']); - } - $cache = $this->getCache(self::JCAT_CACHE_KEY); $result = $cache->getItem(self::PACKAGE_CACHE_KEY, $success); - if (!$success) { + if (!$success || $forceReload) { $config2Html = $this->getConfig2Html(); $staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE"); $packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']); @@ -106,19 +100,14 @@ class CiExecutorService } /** - * @param bool $cached + * @param bool $forceReload * @return array|mixed */ - public function getCiStreams($cached = true) + public function getCiStreams(bool $forceReload = false) { - if (!$cached) { - $config2Html = $this->getConfig2Html(); - return $this->getStreams($config2Html); - } - $cache = $this->getCache(self::STREAM_CACHE_KEY); $result = $cache->getItem(self::STREAM_CACHE_KEY, $success); - if (!$success) { + if (!$success || $forceReload) { $config2Html = $this->getConfig2Html(); $streams =$this->getStreams($config2Html); $cache->setItem(self::STREAM_CACHE_KEY, serialize($streams));