From d90769d2c6e6dfaa47d1a1c67361b635b1b793dc Mon Sep 17 00:00:00 2001 From: mortee Date: Thu, 15 Feb 2024 18:30:11 +0100 Subject: occ news:updater:job exits with code 2 if last update was too long ago Signed-off-by: mortee --- lib/Command/Updater/Job.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Command/Updater/Job.php b/lib/Command/Updater/Job.php index 4404a456e..d6fa4a5aa 100644 --- a/lib/Command/Updater/Job.php +++ b/lib/Command/Updater/Job.php @@ -9,7 +9,10 @@ namespace OCA\News\Command\Updater; use DateTime; +use DateInterval; use OCP\Util; +use OCP\IConfig; +use OCA\News\AppInfo\Application; use OCA\News\Service\StatusService; use OCA\News\Service\UpdaterService; use Symfony\Component\Console\Command\Command; @@ -19,6 +22,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Job extends Command { + /** + * @var IConfig + */ + private $config; + /** * @var StatusService Status service */ @@ -29,9 +37,10 @@ class Job extends Command */ private $updaterService; - public function __construct(StatusService $statusService, UpdaterService $updaterService) + public function __construct(IConfig $config, StatusService $statusService, UpdaterService $updaterService) { parent::__construct(); + $this->config = $config; $this->statusService = $statusService; $this->updaterService = $updaterService; } @@ -64,12 +73,27 @@ class Job extends Command $output->writeln("Checking update Status"); $date = new DateTime(); $date->setTimestamp($this->statusService->getUpdateTime()); - $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e')); + $now = new DateTime('now'); + $elapsedInterval = $now->diff($date); + $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e'). + $elapsedInterval->format("; %h hours, %i minutes, %s seconds ago")); if ($reset) { $output->writeln("Attempting to reset the job."); $this->updaterService->reset(); $output->writeln("Done, job should execute on next schedule."); + } else { + $updateInterval = $this->config->getAppValue( + Application::NAME, + 'updateInterval', + Application::DEFAULT_SETTINGS['updateInterval'] + ); + $threshold = ($updateInterval * 2) + 900; + $elapsedSeconds = $now->getTimestamp() - $date->getTimestamp(); + if ($elapsedSeconds > $threshold) { + $output->writeln("Something's wrong."); + return 2; + } } return 0; } -- cgit v1.2.3