Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleted functions #4691

Merged
merged 18 commits into from
Nov 16, 2022
Merged

Deleted functions #4691

merged 18 commits into from
Nov 16, 2022

Conversation

shimonewman
Copy link
Contributor

Deleted function schedules clean up

schedules clean up
schedules clean up
@shimonewman shimonewman changed the base branch from refactor-functions-worker to feat-db-pools November 16, 2022 14:11
.env Outdated Show resolved Hide resolved
schedules clean up
Comment on lines 923 to 931
],
[
'name' => '_APP_MAINTENANCE_RETENTION_SCHEDULES',
'description' => 'Deleted functions schedule cleanup interval (in seconds) ',
'introduction' => '1.2.0',
'default' => '86400',
'required' => false,
'question' => '',
'filter' => ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a formatting thing. Lets add this variable near the other maintenance variables

Comment on lines 136 to 168
$sum = $limit = 50;
$offset = 0;
/** @var Document[] $functions */
while ($sum >= $limit) {
$schedules = $this->getConsoleDB()->find('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'));

if ($project->isEmpty()) {
Console::success('Deleting schedule for function ' . $schedule->getAttribute('resourceId'));
continue;
}

$function = $this->getProjectDB($project)->getDocument('functions', $schedule->getAttribute('resourceId'));

if ($function->isEmpty()) {
$this->getConsoleDB()->deleteDocument('schedules', $schedule->getId());
Console::success('Deleting schedule for function ' . $schedule->getAttribute('resourceId'));
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a function called deleteByGroup which we can reuse. We don't need to do write the pagination logic again

Copy link
Member

@christyjacob4 christyjacob4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments

shimonewman and others added 5 commits November 16, 2022 16:31
schedules clean up
Co-authored-by: Christy Jacob <christyjacob4@gmail.com>
schedules clean up
schedules clean up
.env Outdated Show resolved Hide resolved
shimonewman and others added 4 commits November 16, 2022 17:08
Co-authored-by: Christy Jacob <christyjacob4@gmail.com>
Co-authored-by: Christy Jacob <christyjacob4@gmail.com>
schedules clean up
@christyjacob4 christyjacob4 merged commit a233a30 into feat-db-pools Nov 16, 2022
@stnguyen90 stnguyen90 deleted the feat-schedules-deletions branch February 14, 2023 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants