diff --git a/app/workers/functions.php b/app/workers/functions.php index 510aed0922..4bacc120b4 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -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']); + } } } }