From b1acc028c966d05273438cf8cf2309730aaf1bb0 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 24 Feb 2022 14:18:46 +0000 Subject: [PATCH] Implement various suggestions + Fix Docblocks + Remove unused variable from deleteRuntime in executor + Added build status explanation to description + Sync composer.phtml to composer.json --- Dockerfile | 4 +- app/views/install/compose.phtml | 14 +----- app/workers/deletes.php | 4 +- src/Appwrite/Utopia/Response/Model/Build.php | 10 ++--- src/Appwrite/Utopia/Response/Model/Func.php | 7 ++- src/Executor/Executor.php | 46 +++++++++++++++++++- 6 files changed, 59 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 38bbb0abe..57e99f4da 100755 --- a/Dockerfile +++ b/Dockerfile @@ -269,6 +269,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/install && \ chmod +x /usr/local/bin/migrate && \ chmod +x /usr/local/bin/realtime && \ + chmod +x /usr/local/bin/executor && \ chmod +x /usr/local/bin/schedule && \ chmod +x /usr/local/bin/sdks && \ chmod +x /usr/local/bin/specs && \ @@ -282,8 +283,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/worker-functions && \ chmod +x /usr/local/bin/worker-builds && \ chmod +x /usr/local/bin/worker-mails && \ - chmod +x /usr/local/bin/worker-webhooks && \ - chmod +x /usr/local/bin/executor + chmod +x /usr/local/bin/worker-webhooks # Letsencrypt Permissions RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 6451d67eb..f3327ac2c 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -174,16 +174,6 @@ services: - appwrite environment: - _APP_ENV - - _APP_OPENSSL_KEY_V1 - - _APP_REDIS_HOST - - _APP_REDIS_PORT - - _APP_REDIS_USER - - _APP_REDIS_PASS - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS - _APP_FUNCTIONS_TIMEOUT - _APP_FUNCTIONS_BUILD_TIMEOUT - _APP_FUNCTIONS_CONTAINERS @@ -193,13 +183,11 @@ services: - _APP_FUNCTIONS_MEMORY_SWAP - _APP_EXECUTOR_SECRET - _APP_EXECUTOR_RUNTIME_NETWORK - - _APP_USAGE_STATS - - _APP_STATSD_HOST - - _APP_STATSD_PORT - _APP_LOGGING_PROVIDER - _APP_LOGGING_CONFIG - DOCKERHUB_PULL_USERNAME - DOCKERHUB_PULL_PASSWORD + - OPENRUNTIMES_INACTIVE_THRESHOLD appwrite-worker-database: image: /: diff --git a/app/workers/deletes.php b/app/workers/deletes.php index d403c1093..de5ce5aeb 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -371,7 +371,7 @@ class DeletesV1 extends Worker $executor = new Executor(); foreach ($deploymentIds as $deploymentId) { try { - $executor->deleteRuntime($projectId, $functionId, $deploymentId); + $executor->deleteRuntime($projectId, $deploymentId); } catch (Throwable $th) { Console::error($th->getMessage()); } @@ -421,7 +421,7 @@ class DeletesV1 extends Worker Console::info("Requesting executor to delete deployment container for deployment " . $deploymentId); try { $executor = new Executor(); - $executor->deleteRuntime($projectId, $functionId, $deploymentId); + $executor->deleteRuntime($projectId, $deploymentId); } catch (Throwable $th) { Console::error($th->getMessage()); } diff --git a/src/Appwrite/Utopia/Response/Model/Build.php b/src/Appwrite/Utopia/Response/Model/Build.php index 218e82d5e..a09ccafa5 100644 --- a/src/Appwrite/Utopia/Response/Model/Build.php +++ b/src/Appwrite/Utopia/Response/Model/Build.php @@ -24,7 +24,7 @@ class Build extends Model ]) ->addRule('deploymentId', [ 'type' => self::TYPE_STRING, - 'description' => 'The deployment that created this build', + 'description' => 'The deployment that created this build.', 'default' => '', 'example' => '5e5ea5c16897e', ]) @@ -35,7 +35,7 @@ class Build extends Model // Building - The deployment is currently being built ->addRule('status', [ 'type' => self::TYPE_STRING, - 'description' => 'The build status.', + 'description' => 'The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built', 'default' => '', 'example' => 'ready', ]) @@ -71,17 +71,17 @@ class Build extends Model * * @return string */ - public function getName():string + public function getName(): string { return 'Build'; } /** - * Get Collection + * Get Type * * @return string */ - public function getType():string + public function getType(): string { return Response::MODEL_BUILD; } diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php index c4afaafc9..c409768b9 100644 --- a/src/Appwrite/Utopia/Response/Model/Func.php +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -122,9 +122,12 @@ class Func extends Model } /** - * Get Collection + * Filter Function * - * @return string + * Automatically converts a [] default to a stdClass, this is called while grabbing the document. + * + * @param Document $document + * @return Document */ public function filter(Document $document): Document { diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 4b3953a35..c731a9ab9 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -31,6 +31,25 @@ class Executor $this->endpoint = $endpoint; } + /** + * Create runtime + * + * Launches a runtime container for a deployment ready for execution + * + * @param string $functionId + * @param string $deploymentId + * @param string $projectId + * @param string $source + * @param string $runtime + * @param string $baseImage + * @param bool $remove + * @param string $entrypoint + * @param string $workdir + * @param string $destinaction + * @param string $network + * @param array $vars + * @param array $commands + */ public function createRuntime( string $functionId, string $deploymentId, @@ -75,7 +94,15 @@ class Executor return $response['body']; } - public function deleteRuntime(string $projectId, string $functionId, string $deploymentId) + /** + * Delete Runtime + * + * Deletes a runtime and cleans up any containers remaining. + * + * @param string $projectId + * @param string $deploymentId + */ + public function deleteRuntime(string $projectId, string $deploymentId) { $runtimeId = "$projectId-$deploymentId"; $route = "/runtimes/$runtimeId"; @@ -96,6 +123,22 @@ class Executor return $response['body']; } + /** + * Create an execution + * + * @param string $projectId + * @param string $functionId + * @param string $deploymentId + * @param string $path + * @param array $vars + * @param string $entrypoint + * @param string $data + * @param string runtime + * @param string $baseImage + * @param int $timeout + * + * @return array + */ public function createExecution( string $projectId, string $functionId, @@ -108,7 +151,6 @@ class Executor string $baseImage, $timeout ) { - $route = "/execution"; $headers = [ 'content-type' => 'application/json',