diff --git a/app/workers/functions.php b/app/workers/functions.php index 537e4ddd9..b34ab45f4 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -1,10 +1,6 @@ list(['label' => 'appwrite-type=function']); -/** @var Container[] $list */ -$list = []; - -foreach ($response as $value) { - $list[$value->getName()] = $value; -} - -$executionEnd = \microtime(true); - -Console::info(count($list) . ' functions listed in ' . ($executionEnd - $executionStart) . ' seconds'); - -/** - * 1. Get event args - DONE - * 2. Unpackage code in the isolated container - DONE - * 3. Execute in container with timeout - * + messure execution time - DONE - * + pass env vars - DONE - * + pass one-time api key - * 4. Update execution status - DONE - * 5. Update execution stdout & stderr - DONE - * 6. Trigger audit log - DONE - * 7. Trigger usage log - DONE - */ - -// TODO avoid scheduled execution if delay is bigger than X offest - class FunctionsV1 extends Worker { public array $args = []; @@ -299,67 +257,6 @@ class FunctionsV1 extends Worker \curl_close($ch); } - /** - * Cleanup any hanging containers above the allowed max containers. - * - * @return void - */ - public function cleanup(): void - { - /** @var Container[] $list */ - global $list; - /** @var Orchestration $orchestration */ - global $orchestration; - - Console::success(count($list) . ' running containers counted'); - - $max = (int) App::getEnv('_APP_FUNCTIONS_CONTAINERS'); - - if (\count($list) > $max) { - Console::info('Starting containers cleanup'); - - \uasort($list, function (Container $item1, Container $item2) { - return (int)($item1->getLabels['appwrite-created'] ?? 0) <=> (int)($item2->getLabels['appwrite-created'] ?? 0); - }); - - while (\count($list) > $max) { - $first = \array_shift($list); - - try { - $orchestration->remove($first->getName(), true); - Console::info('Removed container: ' . $first->getName()); - } catch (Exception $e) { - Console::error('Failed to remove container: ' . $e); - } - } - } - } - - /** - * Filter ENV vars - * - * @param string $string - * - * @return string - */ - public function filterEnvKey(string $string): string - { - if (empty($this->allowed)) { - $this->allowed = array_fill_keys(\str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_'), true); - } - - $string = \str_split($string); - $output = ''; - - foreach ($string as $char) { - if (\array_key_exists($char, $this->allowed)) { - $output .= $char; - } - } - - return $output; - } - public function shutdown(): void { } diff --git a/docker-compose.yml b/docker-compose.yml index 97fe60c81..dd43731b3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -334,6 +334,7 @@ services: depends_on: - redis - mariadb + - appwrite-executor environment: - _APP_ENV - _APP_OPENSSL_KEY_V1