summaryrefslogtreecommitdiffstats
path: root/lib
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 /lib
parent1ae4a36155098bd46c053a6513d2bfdb87f57326 (diff)
occ news:updater:job exits with code 2 if last update was too long ago
Signed-off-by: mortee <mortee@kavemalna.hu>
Diffstat (limited to 'lib')
-rw-r--r--lib/Command/Updater/Job.php28
1 files changed, 26 insertions, 2 deletions
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;
}