summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormortee <mortee@kavemalna.hu>2024-02-15 18:30:11 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2024-02-21 09:16:30 +0100
commitd90769d2c6e6dfaa47d1a1c67361b635b1b793dc (patch)
treed47bd8c5ce58dd768473ebc58f5676e342240873
parent1ae4a36155098bd46c053a6513d2bfdb87f57326 (diff)
occ news:updater:job exits with code 2 if last update was too long ago
Signed-off-by: mortee <mortee@kavemalna.hu>
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/Command/Updater/Job.php28
-rw-r--r--tests/command/update.bats2
3 files changed, 28 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38a70d8e0..6eca1a007 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
# Unreleased
## [25.x.x]
### Changed
+- make occ news:updater:job exit with code 2 if last update was too long ago
### Fixed
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;
@@ -20,6 +23,11 @@ use Symfony\Component\Console\Output\OutputInterface;
class Job extends Command
{
/**
+ * @var IConfig
+ */
+ private $config;
+
+ /**
* @var StatusService Status service
*/
private $statusService;
@@ -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;
}
diff --git a/tests/command/update.bats b/tests/command/update.bats
index d94c1cd28..29b1ae763 100644
--- a/tests/command/update.bats
+++ b/tests/command/update.bats
@@ -11,7 +11,7 @@ TESTSUITE="Update"
@test "[$TESTSUITE] Job status" {
run ./occ news:updater:job
- assert_success
+ [ "$status" -eq 0 -o "$status" -eq 2 ]
}
@test "[$TESTSUITE] Job reset" {