Merge pull request #789 from appwrite/bug-wrong-functions-count-and-deletion
Bug: Wrong functions count and deletion when deleting old containers
This commit is contained in:
commit
200658cadf
1 changed files with 9 additions and 17 deletions
|
@ -283,7 +283,7 @@ class FunctionsV1
|
|||
*/
|
||||
public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $payload = ''): void
|
||||
{
|
||||
global $register, $list;
|
||||
global $list;
|
||||
|
||||
$environments = Config::getParam('environments');
|
||||
|
||||
|
@ -489,29 +489,21 @@ class FunctionsV1
|
|||
if(\count($list) > $max) {
|
||||
Console::info('Starting containers cleanup');
|
||||
|
||||
$sorted = [];
|
||||
|
||||
foreach($list as $env) {
|
||||
$sorted[] = [
|
||||
'name' => $env['name'],
|
||||
'created' => (int)($env['appwrite-created'] ?? 0)
|
||||
];
|
||||
}
|
||||
|
||||
\usort($sorted, function ($item1, $item2) {
|
||||
return $item1['created'] <=> $item2['created'];
|
||||
\usort($list, function ($item1, $item2) {
|
||||
return (int)($item1['appwrite-created'] ?? 0) <=> (int)($item2['appwrite-created'] ?? 0);
|
||||
});
|
||||
|
||||
while(\count($sorted) > $max) {
|
||||
$first = \array_shift($sorted);
|
||||
while(\count($list) > $max) {
|
||||
$first = \array_shift($list);
|
||||
$stdout = '';
|
||||
$stderr = '';
|
||||
|
||||
if(Console::execute("docker stop {$first['name']}", '', $stdout, $stderr, 30) !== 0) {
|
||||
if(Console::execute("docker rm -f {$first['name']}", '', $stdout, $stderr, 30) !== 0) {
|
||||
Console::error('Failed to remove container: '.$stderr);
|
||||
}
|
||||
|
||||
Console::info('Removed container: '.$first['name']);
|
||||
else {
|
||||
Console::info('Removed container: '.$first['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue