From 36200ab4da032615bd09f9a9a5a0f3a7171ae094 Mon Sep 17 00:00:00 2001 From: smarcet Date: Fri, 21 Feb 2020 16:23:42 -0300 Subject: [PATCH] Fixed regenerate summit json command Change-Id: I8c083009cad036e051cade98d74360d88d125481 Signed-off-by: smarcet --- app/Console/Commands/SummitJsonGenerator.php | 54 +++++++++----------- app/Console/Kernel.php | 19 +------ 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/app/Console/Commands/SummitJsonGenerator.php b/app/Console/Commands/SummitJsonGenerator.php index fcfde001..573447b3 100644 --- a/app/Console/Commands/SummitJsonGenerator.php +++ b/app/Console/Commands/SummitJsonGenerator.php @@ -68,7 +68,7 @@ final class SummitJsonGenerator extends Command { * * @var string */ - protected $signature = 'summit:json-generator {summit_id?}'; + protected $signature = 'summit:json-generator'; /** @@ -76,7 +76,7 @@ final class SummitJsonGenerator extends Command { * * @var string */ - protected $description = 'Regenerates Summit Initial Json'; + protected $description = 'Regenerates All Summits Initial Json'; /** * Execute the console command. @@ -85,42 +85,36 @@ final class SummitJsonGenerator extends Command { */ public function handle() { - $summit_id = $this->argument('summit_id'); - if(is_null($summit_id))// if we dont provide a summit id, then get current - $summit = $this->repository->getCurrentAndAvailable(); - else - $summit = $this->repository->getById(intval($summit_id)); + $summits = $this->repository->getAvailables(); - if(is_null($summit)) return; + foreach($summits as $summit) { - if(!$summit->isAvailableOnApi()) return; + $this->info(sprintf("processing summit %s (%s)", $summit->getName(), $summit->getId())); + $start = time(); + $expand = 'schedule'; - $this->info(sprintf("processing summit id %s", $summit->getIdentifier())); - $start = time(); - $expand = 'schedule'; + $data = SerializerRegistry::getInstance()->getSerializer($summit)->serialize($expand); + if (is_null($data)) return; + $end = time(); + $delta = $end - $start; + $this->info(sprintf("execution call %s seconds", $delta)); + $current_time = time(); + $key_current = sprintf('/api/v1/summits/%s.expand=%s', 'current', urlencode($expand)); + $key_id = sprintf('/api/v1/summits/%s.expand=%s', $summit->getIdentifier(), urlencode($expand)); - $data = SerializerRegistry::getInstance()->getSerializer($summit)->serialize($expand); - if(is_null($data)) return; - $end = time(); - $delta = $end - $start; - $this->info(sprintf("execution call %s seconds", $delta)); - $current_time = time(); - $key_current = sprintf('/api/v1/summits/%s.expand=%s','current', urlencode($expand)); - $key_id = sprintf('/api/v1/summits/%s.expand=%s', $summit->getIdentifier(), urlencode($expand)); + $cache_lifetime = intval(Config::get('cache_api_response.get_summit_response_lifetime', 600)); - $cache_lifetime = intval(Config::get('cache_api_response.get_summit_response_lifetime', 600)); + if ($summit->isActive()) { + $this->cache_service->setSingleValue($key_current, gzdeflate(json_encode($data), 9), $cache_lifetime); + $this->cache_service->setSingleValue($key_current . ".generated", $current_time, $cache_lifetime); + } - if($summit->isActive()) - { - $this->cache_service->setSingleValue($key_current, gzdeflate(json_encode($data), 9), $cache_lifetime); - $this->cache_service->setSingleValue($key_current . ".generated", $current_time, $cache_lifetime); + $this->cache_service->setSingleValue($key_id, gzdeflate(json_encode($data), 9), $cache_lifetime); + $this->cache_service->setSingleValue($key_id . ".generated", $current_time, $cache_lifetime); + + $this->info(sprintf("regenerated cache for summit id %s", $summit->getIdentifier())); } - - $this->cache_service->setSingleValue($key_id, gzdeflate(json_encode($data), 9), $cache_lifetime); - $this->cache_service->setSingleValue($key_id.".generated", $current_time, $cache_lifetime); - - $this->info(sprintf("regenerated cache for summit id %s", $summit->getIdentifier())); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index bf2dab50..2e698492 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -47,24 +47,9 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - //Current - $schedule->command('summit:json-generator')->everyFiveMinutes()->withoutOverlapping(); - /** - * REMARK : remember to add new summit ids before they start officially - */ - $summit_ids = [ - 6, //Austin - 7, //BCN - 22, //Boston - 23, //Sydney - 24, //Vancouver BC - 25, //Berlin - 26, //Denver, - 27, //Shanghai - ]; + // regenerate available summits cache - foreach ($summit_ids as $summit_id) - $schedule->command('summit:json-generator',[$summit_id])->everyFiveMinutes()->withoutOverlapping(); + $schedule->command('summit:json-generator')->everyFiveMinutes()->withoutOverlapping(); // list of available summits $schedule->command('summit-list:json-generator')->everyFiveMinutes()->withoutOverlapping();