]> git.mxchange.org Git - friendica.git/commitdiff
Replace cron/worker "last" config entries with key-value entries
authorPhilipp <admin@philipp.info>
Thu, 29 Dec 2022 19:30:19 +0000 (20:30 +0100)
committerPhilipp <admin@philipp.info>
Thu, 29 Dec 2022 20:53:57 +0000 (21:53 +0100)
src/Core/Worker.php
src/Core/Worker/Daemon.php
src/Module/Admin/Summary.php
src/Worker/Cron.php
src/Worker/PullDirectory.php
update.php

index d6f97eed21f289570c2f5540f34e49bb243c08af..cbe6645294fe16b6eb289e5c10d16145aadbc6a3 100644 (file)
@@ -89,9 +89,9 @@ class Worker
                self::$process = $process;
 
                // Kill stale processes every 5 minutes
-               $last_cleanup = DI::config()->get('system', 'worker_last_cleaned', 0);
+               $last_cleanup = DI::keyValue()->get('worker_last_cleaned') ?? 0;
                if (time() > ($last_cleanup + 300)) {
-                       DI::config()->set('system', 'worker_last_cleaned', time());
+                       DI::keyValue()->set( 'worker_last_cleaned', time());
                        Worker\Cron::killStaleWorkers();
                }
 
@@ -388,7 +388,7 @@ class Worker
                        $stamp = (float)microtime(true);
                        $condition = ["`id` = ? AND `next_try` < ?", $queue['id'], DateTimeFormat::utcNow()];
                        if (DBA::update('workerqueue', ['done' => true], $condition)) {
-                               DI::config()->set('system', 'last_worker_execution', DateTimeFormat::utcNow());
+                               DI::keyValue()->set('last_worker_execution', DateTimeFormat::utcNow());
                        }
                        self::$db_duration = (microtime(true) - $stamp);
                        self::$db_duration_write += (microtime(true) - $stamp);
@@ -429,7 +429,7 @@ class Worker
 
                        $stamp = (float)microtime(true);
                        if (DBA::update('workerqueue', ['done' => true], ['id' => $queue['id']])) {
-                               DI::config()->set('system', 'last_worker_execution', DateTimeFormat::utcNow());
+                               DI::keyValue()->set('last_worker_execution', DateTimeFormat::utcNow());
                        }
                        self::$db_duration = (microtime(true) - $stamp);
                        self::$db_duration_write += (microtime(true) - $stamp);
@@ -1422,7 +1422,7 @@ class Worker
                        $duration = max($start, $end) - min($start, $end);
 
                        // Quit when the last cron execution had been after the previous window
-                       $last_cron = DI::config()->get('system', 'last_cron_daily');
+                       $last_cron = DI::keyValue()->get('last_cron_daily');
                        if ($last_cron + $duration > time()) {
                                Logger::info('The Daily cron had been executed recently', ['last' => date(DateTimeFormat::MYSQL, $last_cron), 'start' => date('H:i:s', $start), 'end' => date('H:i:s', $end)]);
                                return false;
index 6fd64e4f595bdb4664aa73a944d955ab2804c462..858acc25d713f79c4d5f5c5b0e4769e848228b8e 100644 (file)
@@ -93,11 +93,11 @@ class Daemon
                }
 
                // Check every minute if the daemon is running
-               if (DI::config()->get('system', 'last_daemon_check', 0) + 60 > time()) {
+               if ((DI::keyValue()->get('last_daemon_check') ?? 0) + 60 > time()) {
                        return;
                }
 
-               DI::config()->set('system', 'last_daemon_check', time());
+               DI::keyValue()->set('last_daemon_check', time());
 
                $pidfile = DI::config()->get('system', 'pidfile');
                if (empty($pidfile)) {
index d27a9b011ba6c008ccb5afa3e1fa62af0d0601a0..42098c95cd299ddfa7306861d28ec3f287300372 100644 (file)
@@ -98,7 +98,7 @@ class Summary extends BaseAdmin
                        $warningtext[] = DI::l10n()->t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)');
                }
 
-               $last_worker_call = DI::config()->get('system', 'last_worker_execution', false);
+               $last_worker_call = DI::keyValue()->get('last_worker_execution') ?? false;
                if (!$last_worker_call) {
                        $warningtext[] = DI::l10n()->t('The worker was never executed. Please check your database structure!');
                } elseif ((strtotime(DateTimeFormat::utcNow()) - strtotime($last_worker_call)) > 60 * 60) {
index 94f002805b4baf2974eb823e6e051833906e359a..055a9b4354ed66556ac450bee8e19c4b391e58c4 100644 (file)
@@ -37,7 +37,7 @@ class Cron
        {
                $a = DI::app();
 
-               $last = DI::config()->get('system', 'last_cron');
+               $last = DI::keyValue()->get('last_cron');
 
                $poll_interval = intval(DI::config()->get('system', 'cron_interval'));
 
@@ -84,7 +84,7 @@ class Cron
                Worker::add(Worker::PRIORITY_LOW, 'PostUpdate');
 
                // Hourly cron calls
-               if (DI::config()->get('system', 'last_cron_hourly', 0) + 3600 < time()) {
+               if ((DI::keyValue()->get('last_cron_hourly') ?? 0) + 3600 < time()) {
 
 
                        // Update trending tags cache for the community page
@@ -105,7 +105,7 @@ class Cron
                        // Clear cache entries
                        Worker::add(Worker::PRIORITY_LOW, 'ClearCache');
 
-                       DI::config()->set('system', 'last_cron_hourly', time());
+                       DI::keyValue()->set('last_cron_hourly', time());
                }
 
                // Daily maintenance cron calls
@@ -145,12 +145,12 @@ class Cron
                        // Resubscribe to relay servers
                        Relay::reSubscribe();
 
-                       DI::config()->set('system', 'last_cron_daily', time());
+                       DI::keyValue()->set('last_cron_daily', time());
                }
 
                Logger::notice('end');
 
-               DI::config()->set('system', 'last_cron', time());
+               DI::keyValue()->set('last_cron', time());
        }
 
        /**
index 8a22e504c0454fa72e89b3c6bdc55a1672ea8d3e..d174d11f3e5d36a67b898f5d2883667b3f9dff73 100644 (file)
@@ -45,7 +45,7 @@ class PullDirectory
                        return;
                }
 
-               $now = (int)DI::config()->get('system', 'last-directory-sync', 0);
+               $now = (int)(DI::keyValue()->get('last-directory-sync') ?? 0);
 
                Logger::info('Synchronization started.', ['now' => $now, 'directory' => $directory]);
 
@@ -64,7 +64,7 @@ class PullDirectory
                $result = Contact::addByUrls($contacts['results']);
 
                $now = $contacts['now'] ?? 0;
-               DI::config()->set('system', 'last-directory-sync', $now);
+               DI::keyValue()->set('last-directory-sync', $now);
 
                Logger::info('Synchronization ended', ['now' => $now, 'count' => $result['count'], 'added' => $result['added'], 'updated' => $result['updated'], 'unchanged' => $result['unchanged'], 'directory' => $directory]);
        }
index fb62f28df46191053eac105f31a815750398cb0b..632d173a71ed5180fa22fd9c76a5861245e606eb 100644 (file)
@@ -1148,11 +1148,19 @@ function update_1502()
 
 function update_1505()
 {
-       $postUpdateEntries = DBA::selectToArray('config', ['k', 'v'], ["`k` LIKE ?", "post_update_%"]);
+       $conditions = [
+               "(`k` LIKE ?) OR (`k` = ?) OR (`cat` = ? AND `k` LIKE ?)",
+               "post_update_%",
+               "worker_last_cleaned",
+               "system",
+               "last%"
+       ];
+
+       $postUpdateEntries = DBA::selectToArray('config', ['k', 'v'], $conditions);
 
        foreach ($postUpdateEntries as $postUpdateEntry) {
                DI::keyValue()->set($postUpdateEntry['k'], $postUpdateEntry['v']);
        }
 
-       return DBA::delete('config', ["`k` LIKE ?", "post_update_%"]) ? Update::SUCCESS : Update::FAILED;
+       return DBA::delete('config', $conditions) ? Update::SUCCESS : Update::FAILED;
 }