From a3fc3daf82f7e182ee46efff637861934f7c2674 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 7 Jan 2025 13:15:16 +0900 Subject: [PATCH] Make 0 equal unlimited for functions environment variables --- app/controllers/api/functions.php | 4 +++- src/Appwrite/Functions/Validator/RuntimeSpecification.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d4d5fc64cf..62dc0b7deb 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -550,7 +550,9 @@ App::get('/v1/functions/specifications') } // Only add specs that are within the limits set by environment variables - if ($spec['cpus'] <= System::getEnv('_APP_FUNCTIONS_CPUS', 1) && $spec['memory'] <= System::getEnv('_APP_FUNCTIONS_MEMORY', 512)) { + if ( + ($spec['cpus'] <= System::getEnv('_APP_FUNCTIONS_CPUS', 1) || System::getEnv('_APP_FUNCTIONS_CPUS', 1) === 0) && + ($spec['memory'] <= System::getEnv('_APP_FUNCTIONS_MEMORY', 512)) || System::getEnv('_APP_FUNCTIONS_MEMORY', 512) === 0) { $runtimeSpecs[] = $spec; } } diff --git a/src/Appwrite/Functions/Validator/RuntimeSpecification.php b/src/Appwrite/Functions/Validator/RuntimeSpecification.php index 22311838f6..a41ea0a540 100644 --- a/src/Appwrite/Functions/Validator/RuntimeSpecification.php +++ b/src/Appwrite/Functions/Validator/RuntimeSpecification.php @@ -34,7 +34,7 @@ class RuntimeSpecification extends Validator $allowedSpecifications = []; foreach ($this->specifications as $size => $values) { - if ($values['cpus'] <= $this->maxCpus && $values['memory'] <= $this->maxMemory) { + if (($values['cpus'] <= $this->maxCpus || $this->maxCpus === 0) && ($values['memory'] <= $this->maxMemory || $this->maxMemory === 0)) { if (!empty($this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { if (!\in_array($size, $this->plan['runtimeSpecifications'])) { continue;