1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00

Deleted functions

schedules clean up
This commit is contained in:
shimon 2022-11-16 16:31:49 +02:00
parent dd7bd108cc
commit 99823656f0
2 changed files with 15 additions and 22 deletions

View file

@ -923,7 +923,7 @@ return [
],
[
'name' => '_APP_MAINTENANCE_RETENTION_SCHEDULES',
'description' => 'Deleted functions schedule cleanup interval (in seconds) ',
'description' => 'Schedules deletion interval ( in seconds ) ',
'introduction' => '1.2.0',
'default' => '86400',
'required' => false,

View file

@ -133,39 +133,32 @@ class DeletesV1 extends Worker
protected function deleteSchedules(string $datetime): void
{
$sum = $limit = 50;
$offset = 0;
/** @var Document[] $functions */
while ($sum >= $limit) {
$schedules = $this->getConsoleDB()->find('schedules', [
$this->deleteByGroup(
'schedules',
[
Query::equal('region', [App::getEnv('_APP_REGION', 'default')]),
Query::equal('resourceType', ['function']),
Query::lessThanEqual('resourceUpdatedAt', $datetime),
Query::equal('active', [false]),
Query::limit($limit),
Query::offset($offset),
]);
$sum = \count($schedules);
$offset = $offset + $limit;
foreach ($schedules as $schedule) {
Console::info('Querying schedule for function ' . $schedule->getAttribute('resourceId'));
$project = $this->getConsoleDB()->getDocument('projects', $schedule->getAttribute('projectId'));
],
$this->getConsoleDB(),
function (Document $document) {
Console::info('Querying schedule for function ' . $document->getAttribute('resourceId'));
$project = $this->getConsoleDB()->getDocument('projects', $document->getAttribute('projectId'));
if ($project->isEmpty()) {
Console::success('Deleting schedule for function ' . $schedule->getAttribute('resourceId'));
continue;
Console::success('Deleting schedule for function ' . $document->getAttribute('resourceId'));
return;
}
$function = $this->getProjectDB($project)->getDocument('functions', $schedule->getAttribute('resourceId'));
$function = $this->getProjectDB($project)->getDocument('functions', $document->getAttribute('resourceId'));
if ($function->isEmpty()) {
$this->getConsoleDB()->deleteDocument('schedules', $schedule->getId());
Console::success('Deleting schedule for function ' . $schedule->getAttribute('resourceId'));
$this->getConsoleDB()->deleteDocument('schedules', $document->getId());
Console::success('Deleting schedule for function ' . $document->getAttribute('resourceId'));
}
}
}
);
}
/**