[TikiWiki-commits] [Git][tikiwiki/tiki][master] [NEW] Scheduler: add monitor command
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68c989e2106af_2cdea1c984a3@gitlab-sidekiq-low-urgency-cpu-bound-v2-6849cbcf9c-xh4x7.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
e7cbce8a by Josaphat Imani at 2025-09-16T15:53:18+00:00
[NEW] Scheduler: add monitor command
---
* Fix return value for command
* [NEW] Scheduler: add monitor command
See merge request tikiwiki/tiki!8005
- - - - -
3 changed files:
- lib/core/Tiki/Command/ConsoleApplicationBuilder.php
- + lib/core/Tiki/Command/SchedulerMonitorCommand.php
- lib/schedulerslib.php
Changes:
=====================================
lib/core/Tiki/Command/ConsoleApplicationBuilder.php
=====================================
@@ -209,6 +209,7 @@ class ConsoleApplicationBuilder
new SieveFiltersCommand(),
new CalendarSyncCommand(),
new SchedulerRunCommand(),
+ new SchedulerMonitorCommand(),
new WebmailUnreadPagesCommand(),
new WebmailUnreadGlobalCommand(),
new Disable2FACommand(),
=====================================
lib/core/Tiki/Command/SchedulerMonitorCommand.php
=====================================
@@ -0,0 +1,72 @@
+<?php
+
+// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
+//
+// All Rights Reserved. See copyright.txt for details and a complete list of authors.
+// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+namespace Tiki\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Attribute\AsCommand;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+#[AsCommand(
+ name: 'scheduler:monitor',
+ description: 'Monitor scheduler jobs'
+)]
+class SchedulerMonitorCommand extends Command
+{
+ protected function configure()
+ {
+ $this
+ ->addOption(
+ 'minutes-back',
+ 'm',
+ InputOption::VALUE_REQUIRED,
+ 'Number of minutes back to check for failed tasks'
+ );
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int
+ {
+ global $prefs;
+
+ if ($prefs['feature_scheduler'] != 'y') {
+ $output->writeln("<error>Scheduler feature is not enabled.</error>");
+ return Command::FAILURE;
+ }
+
+ $io = new SymfonyStyle($input, $output);
+ $minutesBack = (int) $input->getOption('minutes-back') ?: 0;
+
+ if ($minutesBack === 0) {
+ $output->writeln(tr('Option "minutes-back" is not valid. Insert a valid numeric number greater than 0'));
+ return Command::FAILURE;
+ }
+
+ $timestampBack = time() - ($minutesBack * 60);
+ $schedLib = \TikiLib::lib('scheduler');
+ $results = $schedLib->getFailedRuns($timestampBack);
+
+ $message = "";
+ foreach ($results as $key => $run) {
+ $seconds = $run['end_time'] - $run['start_time'];
+ $scheduler = $schedLib->get_scheduler($run['scheduler_id']);
+ if ($key != 0) {
+ $message .= "\n";
+ }
+ $message .= "Scheduler $scheduler[name] failed after $seconds seconds";
+ $message .= "\nReason: $run[output]";
+ }
+
+ if (count($results) == 0) {
+ return Command::SUCCESS;
+ }
+
+ $output->writeln($message);
+ return Command::FAILURE;
+ }
+}
=====================================
lib/schedulerslib.php
=====================================
@@ -149,6 +149,26 @@ class SchedulersLib extends TikiLib
return $schedulersRunTable->fetchOne('status', ['scheduler_id' => $scheduler_id], ['id' => 'DESC']);
}
+ /**
+ * Get failed runs
+ *
+ * @param int $scheduler_id The Scheduler Id
+ *
+ * @return bool|mixed
+ */
+ public function getFailedRuns($timeBack)
+ {
+ $schedulersRunTable = $this->table('tiki_scheduler_run');
+
+ return $schedulersRunTable->fetchAll(
+ ['start_time', 'end_time', 'output', 'scheduler_id'],
+ [
+ 'start_time' => $schedulersRunTable->greaterThan($timeBack),
+ 'status' => 'failed'
+ ]
+ );
+ }
+
/**
* Mark scheduler run as active (running)
*
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e7cbce8a29257afaf66654b93142d7d7590abe09
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e7cbce8a29257afaf66654b93142d7d7590abe09
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs