1
0
Fork 0
mirror of synced 2024-06-26 18:20:43 +12:00

Fixed container deletion

This commit is contained in:
Eldad Fux 2020-12-30 12:44:33 +02:00
parent bf7282c04f
commit d0fd81ce91

View file

@ -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,30 @@ 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);
}
Console::info('Removed container: '.$first['name']);
else {
Console::info('Removed container: '.$first['name']);
}
}
}
}