summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormortee <mortee@kavemalna.hu>2024-02-16 12:42:33 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2024-02-21 09:16:30 +0100
commit540b7db34e5905fd12114f1dad99d73e58531bad (patch)
tree009ddb9addd67e0490409b0a890209b03a5184d6
parent9ee51e0c5b4e761a250fdd0413b45979dc33bb17 (diff)
added --check-elapsed command line option, to prevent existing scripts from breaking
-rw-r--r--docs/troubleshooting.md12
-rw-r--r--lib/Command/Updater/Job.php35
2 files changed, 35 insertions, 12 deletions
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 5dad1604f..39677b564 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -73,6 +73,18 @@ Checking update Status
Last Execution was 2023-03-20 12:20:03 UTC
```
+The same check that is done in the News admin settings can be done using occ too.
+Adding the --check-elapsed option displays the time elapsed since the last execution,
+and if it's considered too long ago, a message will be displayed, and the command returns
+with exit code 2. This can be used in scripts to send an alert for example.
+```bash
+sudo -u www-data php ./occ news:updater:job --check-elapsed
+Checking update Status
+Last Execution was 2023-03-20 12:20:03 UTC
+8 hours, 21 minutes, 20 seconds ago
+Something is wrong with the news cronjob, execution delay exceeded the configured interval.
+```
+
If you think the job is stuck you can reset it, this may lead to issues if the job is currently running!
```bash
diff --git a/lib/Command/Updater/Job.php b/lib/Command/Updater/Job.php
index 0a8e352a6..4794de034 100644
--- a/lib/Command/Updater/Job.php
+++ b/lib/Command/Updater/Job.php
@@ -57,12 +57,19 @@ class Job extends Command
InputOption::VALUE_NONE,
'If the job should be reset, warning this might lead to issues.'
)
+ ->addOption(
+ 'check-elapsed',
+ null,
+ InputOption::VALUE_NONE,
+ 'Check if the last job execution was too long ago. Return exit code 2 if so.'
+ )
->setDescription('Console API for checking the update job status and to reset it.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$reset = (bool) $input->getOption('reset');
+ $checkElapsed = (bool) $input->getOption('check-elapsed');
[$major, $minor, $micro] = Util::getVersion();
@@ -75,8 +82,10 @@ class Job extends Command
$date->setTimestamp($this->statusService->getUpdateTime());
$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"));
+ $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e'));
+ if ($checkElapsed) {
+ $output->writeln($elapsedInterval->format('%h hours, %i minutes, %s seconds ago'));
+ }
if ($reset) {
$output->writeln("Attempting to reset the job.");
@@ -85,16 +94,18 @@ class Job extends Command
return 0;
}
- $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 is wrong with the news cronjob, execution delay exceeded the configured interval.");
- return 2;
+ if ($checkElapsed) {
+ $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 is wrong with the news cronjob, execution delay exceeded the configured interval.");
+ return 2;
+ }
}
return 0;