Fixed container deletion
This commit is contained in:
parent
bf7282c04f
commit
d0fd81ce91
1 changed files with 16 additions and 15 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,32 +489,33 @@ class FunctionsV1
|
|||
if(\count($list) > $max) {
|
||||
Console::info('Starting containers cleanup');
|
||||
|
||||
$sorted = [];
|
||||
// $sorted = [];
|
||||
|
||||
foreach($list as $env) {
|
||||
$sorted[] = [
|
||||
'name' => $env['name'],
|
||||
'created' => (int)($env['appwrite-created'] ?? 0)
|
||||
];
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
else {
|
||||
Console::info('Removed container: '.$first['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter ENV vars
|
||||
|
|
Loading…
Reference in a new issue