* cache refresh extended to jcat and streams

This commit is contained in:
Dávid Danyi 2017-03-30 16:04:07 +02:00
parent 68e66ddedf
commit 47efbfecc4
4 changed files with 15 additions and 24 deletions

View File

@ -4,12 +4,12 @@ return [
'dependencies' => [ 'dependencies' => [
'invokables' => [], 'invokables' => [],
'factories' => [ 'factories' => [
App\Command\UpdateNightlyCacheCommand::class => App\Command\UpdateNightlyCacheCommandFactory::class, App\Command\UpdateCacheCommand::class => App\Command\UpdateCacheCommandFactory::class,
], ],
], ],
'console' => [ 'console' => [
'commands' => [ 'commands' => [
App\Command\UpdateNightlyCacheCommand::class, App\Command\UpdateCacheCommand::class,
], ],
], ],
]; ];

View File

@ -7,7 +7,7 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class UpdateNightlyCacheCommand extends Command class UpdateCacheCommand extends Command
{ {
/** /**
* @var CiExecutorService * @var CiExecutorService
@ -22,12 +22,14 @@ class UpdateNightlyCacheCommand extends Command
protected function configure() protected function configure()
{ {
$this->setName('nightly:update') $this->setName('cache:update')
->setDescription('Updates nightly configuration cache'); ->setDescription('Updates cache of jcat packages, streams and active nightly ci configuration');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->ciExecutorService->getActiveNightlyConfiguration(true); $this->ciExecutorService->getActiveNightlyConfiguration(true);
$this->ciExecutorService->getCiStreams(false);
$this->ciExecutorService->getJcatPackages(false);
} }
} }

View File

@ -5,12 +5,12 @@ namespace App\Command;
use App\Service\CiExecutorService; use App\Service\CiExecutorService;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
class UpdateNightlyCacheCommandFactory class UpdateCacheCommandFactory
{ {
public function __invoke(ContainerInterface $container) public function __invoke(ContainerInterface $container)
{ {
/** @var CiExecutorService $ciExecutorService */ /** @var CiExecutorService $ciExecutorService */
$ciExecutorService = $container->get(CiExecutorService::class); $ciExecutorService = $container->get(CiExecutorService::class);
return new UpdateNightlyCacheCommand($ciExecutorService); return new UpdateCacheCommand($ciExecutorService);
} }
} }

View File

@ -81,20 +81,14 @@ class CiExecutorService
/** /**
* Get available jcat versions from config2 page * Get available jcat versions from config2 page
* *
* @param bool $cached * @param bool $forceReload
* @return array * @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); $cache = $this->getCache(self::JCAT_CACHE_KEY);
$result = $cache->getItem(self::PACKAGE_CACHE_KEY, $success); $result = $cache->getItem(self::PACKAGE_CACHE_KEY, $success);
if (!$success) { if (!$success || $forceReload) {
$config2Html = $this->getConfig2Html(); $config2Html = $this->getConfig2Html();
$staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE"); $staplerTokens = $this->getStaplerTokens($config2Html, "JCAT_TYPE");
$packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']); $packages =$this->getJcatVersions($staplerTokens['url'], $staplerTokens['token']);
@ -106,19 +100,14 @@ class CiExecutorService
} }
/** /**
* @param bool $cached * @param bool $forceReload
* @return array|mixed * @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); $cache = $this->getCache(self::STREAM_CACHE_KEY);
$result = $cache->getItem(self::STREAM_CACHE_KEY, $success); $result = $cache->getItem(self::STREAM_CACHE_KEY, $success);
if (!$success) { if (!$success || $forceReload) {
$config2Html = $this->getConfig2Html(); $config2Html = $this->getConfig2Html();
$streams =$this->getStreams($config2Html); $streams =$this->getStreams($config2Html);
$cache->setItem(self::STREAM_CACHE_KEY, serialize($streams)); $cache->setItem(self::STREAM_CACHE_KEY, serialize($streams));