loop through projects
This commit is contained in:
parent
5c3bd741b4
commit
5512123e04
1 changed files with 38 additions and 5 deletions
|
@ -44,18 +44,51 @@ class Maintenance extends Action
|
||||||
$time = DateTime::now();
|
$time = DateTime::now();
|
||||||
|
|
||||||
Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds");
|
Console::info("[{$time}] Notifying workers with maintenance tasks every {$interval} seconds");
|
||||||
|
|
||||||
|
$this->foreachProject($dbForConsole, function (Document $project) use ($queueForDeletes, $usageStatsRetentionHourly) {
|
||||||
|
$queueForDeletes->setProject($project);
|
||||||
|
|
||||||
$this->notifyDeleteExecutionLogs($queueForDeletes);
|
$this->notifyDeleteExecutionLogs($queueForDeletes);
|
||||||
$this->notifyDeleteAbuseLogs($queueForDeletes);
|
$this->notifyDeleteAbuseLogs($queueForDeletes);
|
||||||
$this->notifyDeleteAuditLogs($queueForDeletes);
|
$this->notifyDeleteAuditLogs($queueForDeletes);
|
||||||
$this->notifyDeleteUsageStats($usageStatsRetentionHourly, $queueForDeletes);
|
$this->notifyDeleteUsageStats($usageStatsRetentionHourly, $queueForDeletes);
|
||||||
$this->notifyDeleteConnections($queueForDeletes);
|
|
||||||
$this->notifyDeleteExpiredSessions($queueForDeletes);
|
$this->notifyDeleteExpiredSessions($queueForDeletes);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->notifyDeleteConnections($queueForDeletes);
|
||||||
$this->renewCertificates($dbForConsole, $queueForCertificates);
|
$this->renewCertificates($dbForConsole, $queueForCertificates);
|
||||||
$this->notifyDeleteCache($cacheRetention, $queueForDeletes);
|
$this->notifyDeleteCache($cacheRetention, $queueForDeletes);
|
||||||
$this->notifyDeleteSchedules($schedulesDeletionRetention, $queueForDeletes);
|
$this->notifyDeleteSchedules($schedulesDeletionRetention, $queueForDeletes);
|
||||||
}, $interval);
|
}, $interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function foreachProject(Database $dbForConsole, callable $callback): void
|
||||||
|
{
|
||||||
|
// TODO: @Meldiron name of this method no longer matches. It does not delete, and it gives whole document
|
||||||
|
$count = 0;
|
||||||
|
$chunk = 0;
|
||||||
|
$limit = 50;
|
||||||
|
$sum = $limit;
|
||||||
|
$executionStart = \microtime(true);
|
||||||
|
|
||||||
|
while ($sum === $limit) {
|
||||||
|
$projects = $dbForConsole->find('projects', [Query::limit($limit), Query::offset($chunk * $limit)]);
|
||||||
|
|
||||||
|
$chunk++;
|
||||||
|
|
||||||
|
/** @var string[] $projectIds */
|
||||||
|
$sum = count($projects);
|
||||||
|
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
$callback($project);
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$executionEnd = \microtime(true);
|
||||||
|
Console::info("Found {$count} projects " . ($executionEnd - $executionStart) . " seconds");
|
||||||
|
}
|
||||||
|
|
||||||
private function notifyDeleteExecutionLogs(Delete $queueForDeletes): void
|
private function notifyDeleteExecutionLogs(Delete $queueForDeletes): void
|
||||||
{
|
{
|
||||||
($queueForDeletes)
|
($queueForDeletes)
|
||||||
|
|
Loading…
Reference in a new issue