From a0296d634694fe9056e4e145d53530cc24be516e Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 25 Jan 2022 22:44:21 +0400 Subject: [PATCH] feat: refactor the executor --- app/executor.php | 29 ++++++++--------------------- app/workers/builds.php | 20 ++------------------ 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/app/executor.php b/app/executor.php index c533806bcc..4e4a29625b 100644 --- a/app/executor.php +++ b/app/executor.php @@ -1050,6 +1050,7 @@ App::post('/v1/cleanup/tag') }); App::post('/v1/tag') + ->desc('Create a new build') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('tagId', '', new UID(), 'Tag unique ID.') ->param('userId', '', new UID(), 'User unique ID.', true) @@ -1170,20 +1171,9 @@ App::post('/v1/tag') $response->dynamic($function, Response::MODEL_FUNCTION); }); -App::get('/v1/') - ->inject('response') - ->action( - function (Response $response) { - $response - ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') - ->addHeader('Expires', '0') - ->addHeader('Pragma', 'no-cache') - ->json(['status' => 'online']); - } - ); - // Build Endpoints App::post('/v1/build/:buildId') // Start a Build + ->desc('Start a build') ->param('buildId', '', new UID(), 'Build unique ID.', false) ->inject('response') ->inject('dbForProject') @@ -1213,16 +1203,13 @@ App::post('/v1/build/:buildId') // Start a Build runBuildStage($buildId, $projectID, $dbForProject); }); - // return success - return $response->json(['success' => true]); - } catch (Exception $e) { - logError($e, "buildEndpoint"); - $response - ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') - ->addHeader('Expires', '0') - ->addHeader('Pragma', 'no-cache') - ->json(['error' => $e->getMessage()]); + ->setStatusCode(Response::STATUS_CODE_CREATED) + ->send(); + } catch (Exception $e) { + // TODO : @matej,why do we need to log here ? There is a global error handler that logs errors + logError($e, "buildEndpoint"); + throw $e; } }); diff --git a/app/workers/builds.php b/app/workers/builds.php index 7aec17e8f3..6a37a63908 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -59,7 +59,7 @@ class BuildsV1 extends Worker { // TODO: What is a reasonable time to wait for a build to complete? $ch = \curl_init(); - \curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor:8080/v1/build/$buildId"); + \curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor/v1/build/$buildId"); \curl_setopt($ch, CURLOPT_POST, true); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); \curl_setopt($ch, CURLOPT_TIMEOUT, 900); @@ -80,20 +80,9 @@ class BuildsV1 extends Worker \curl_close($ch); - if ($responseStatus !== 200) { + if ($responseStatus >= 400) { throw new \Exception("Build failed with status code: $responseStatus"); } - - $response = json_decode($response, true); - if (isset($response['error'])) { - throw new \Exception($response['error']); - } - - if (isset($response['success']) && $response['success'] === true) { - return; - } else { - throw new \Exception("Build failed"); - } } protected function triggerCreateRuntimeServer(string $projectId, string $functionId, string $tagId) @@ -127,11 +116,6 @@ class BuildsV1 extends Worker if ($responseStatus >= 400) { throw new \Exception("Build failed with status code: $responseStatus"); } - - $response = json_decode($response, true); - if (isset($response['error'])) { - throw new \Exception($response['error']); - } } protected function buildTag(string $projectId, string $functionId, string $tagId)