feat: refactor the executor

This commit is contained in:
Christy Jacob
2022-01-25 22:44:21 +04:00
parent e0c5500809
commit a0296d6346
2 changed files with 10 additions and 39 deletions
+8 -21
View File
@@ -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;
}
});
+2 -18
View File
@@ -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)