]> source.dussan.org Git - nextcloud-server.git/commitdiff
Warn admins about delayed cron executions
authorJoas Schilling <coding@schilljs.com>
Thu, 6 Feb 2020 19:10:30 +0000 (20:10 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Sat, 8 Feb 2020 09:21:54 +0000 (10:21 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/settings/lib/Settings/Admin/Server.php
apps/settings/templates/settings/admin/server.php

index 6216af4aada06d47c2978a8bb96fff415e1daef3..40333e1043cd6f7200cfe35380afcf27aa7be8d2 100644 (file)
@@ -29,16 +29,19 @@ namespace OCA\Settings\Settings\Admin;
 
 use OCP\AppFramework\Http\TemplateResponse;
 use OCP\IConfig;
+use OCP\IDBConnection;
 use OCP\Settings\ISettings;
 
 class Server implements ISettings {
+
+       /** @var IDBConnection */
+       private $connection;
        /** @var IConfig */
        private $config;
 
-       /**
-        * @param IConfig $config
-        */
-       public function __construct(IConfig $config) {
+       public function __construct(IDBConnection $connection,
+                                                               IConfig $config) {
+               $this->connection = $connection;
                $this->config = $config;
        }
 
@@ -46,10 +49,25 @@ class Server implements ISettings {
         * @return TemplateResponse
         */
        public function getForm() {
+               $query = $this->connection->getQueryBuilder();
+               $query->select('last_checked')
+                       ->from('jobs')
+                       ->orderBy('last_checked', 'ASC')
+                       ->setMaxResults(1);
+
+               $result = $query->execute();
+               if ($row = $result->fetch()) {
+                       $maxAge = (int) $row['last_checked'];
+               } else {
+                       $maxAge = time();
+               }
+               $result->closeCursor();
+
                $parameters = [
                        // Background jobs
                        'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
                        'lastcron'            => $this->config->getAppValue('core', 'lastcron', false),
+                       'cronMaxAge'          => $maxAge,
                        'cronErrors'              => $this->config->getAppValue('core', 'cronErrors'),
                        'cli_based_cron_possible' => function_exists('posix_getpwuid'),
                        'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
index 92bf433ca6c1ac0e3af3fc17b5b39a6375d7b39f..513e82ece5a9d76d437a3482a03db009b4ec3426 100644 (file)
 <div class="section" id="backgroundjobs">
        <h2 class="inlineblock"><?php p($l->t('Background jobs'));?></h2>
        <p class="cronlog inlineblock">
-               <?php if ($_['lastcron'] !== false):
+               <?php if ($_['lastcron'] !== false) {
                        $relative_time = relative_modified_date($_['lastcron']);
+                       $maxAgeRelativeTime = relative_modified_date($_['cronMaxAge']);
 
                        $formatter = \OC::$server->getDateTimeFormatter();
                        $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long');
-                       if (time() - $_['lastcron'] <= 600): ?>
-                               <span class="status success"></span>
-                               <span class="crondate" title="<?php p($absolute_time);?>">
-                               <?php p($l->t("Last job ran %s.", [$relative_time]));?>
-                       </span>
-                       <?php else: ?>
+                       $maxAgeAbsoluteTime = $formatter->formatDateTime($_['cronMaxAge'], 'long', 'long');
+                       if (time() - $_['lastcron'] > 600) { ?>
                                <span class="status error"></span>
                                <span class="crondate" title="<?php p($absolute_time);?>">
-                               <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?>
-                       </span>
-                       <?php endif;
-               else: ?>
+                                       <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?>
+                               </span>
+                       <?php } else if (time() - $_['cronMaxAge'] > 12*3600) {
+                                       if ($_['backgroundjobs_mode'] === 'cron') { ?>
+                                               <span class="status warning"></span>
+                                               <span class="crondate" title="<?php p($maxAgeAbsoluteTime);?>">
+                                                       <?php p($l->t("Some jobs haven’t been executed since %s. Please consider increasing the execution frequency.", [$maxAgeRelativeTime]));?>
+                                               </span>
+                                       <?php } else { ?>
+                                               <span class="status error"></span>
+                                               <span class="crondate" title="<?php p($maxAgeAbsoluteTime);?>">
+                                                       <?php p($l->t("Some jobs didn’t execute since %s. Please consider switching to system cron.", [$maxAgeRelativeTime]));?>
+                                               </span>
+                                       <?php }
+                       } else { ?>
+                               <span class="status success"></span>
+                               <span class="crondate" title="<?php p($absolute_time);?>">
+                                       <?php p($l->t("Last job ran %s.", [$relative_time]));?>
+                               </span>
+                       <?php }
+               } else { ?>
                        <span class="status error"></span>
                        <?php p($l->t("Background job didn’t run yet!"));
-               endif; ?>
+               } ?>
        </p>
        <a target="_blank" rel="noreferrer noopener" class="icon-info"
           title="<?php p($l->t('Open documentation'));?>"