Replace cron/worker "last" config entries with key-value entries

This commit is contained in:
Philipp 2022-12-29 20:30:19 +01:00
parent 10f8631cd9
commit 6b3265742a
No known key found for this signature in database
GPG Key ID: 24A7501396EB5432
6 changed files with 25 additions and 17 deletions

View 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;

View 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)) {

View 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) {

View 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());
}
/**

View 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]);
}

View 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;
}