feat: move retry build call to builds worker
This commit is contained in:
parent
abd54938ef
commit
b59566a815
|
@ -593,7 +593,7 @@ App::post('/v1/functions/:functionId/tags')
|
|||
'projectId' => $project->getId(),
|
||||
'functionId' => $function->getId(),
|
||||
'tagId' => $tagId,
|
||||
'type' => 'tag'
|
||||
'type' => BUILD_TYPE_TAG
|
||||
]);
|
||||
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
|
@ -1134,34 +1134,12 @@ App::post('/v1/builds/:buildId')
|
|||
throw new Exception('Build not failed', 400);
|
||||
}
|
||||
|
||||
// Retry build
|
||||
$ch = \curl_init();
|
||||
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor:8080/v1/build/{$buildId}");
|
||||
\curl_setopt($ch, CURLOPT_POST, true);
|
||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
\curl_setopt($ch, CURLOPT_TIMEOUT, 900);
|
||||
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
\curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json',
|
||||
'x-appwrite-project: '.$project->getId(),
|
||||
'x-appwrite-executor-key: '. App::getEnv('_APP_EXECUTOR_SECRET', '')
|
||||
// Enqueue a message to start the build
|
||||
Resque::enqueue('v1-builds', 'BuildsV1', [
|
||||
'projectId' => $project->getId(),
|
||||
'buildId' => $buildId,
|
||||
'type' => BUILD_TYPE_RETRY
|
||||
]);
|
||||
|
||||
$executorResponse = \curl_exec($ch);
|
||||
|
||||
$error = \curl_error($ch);
|
||||
|
||||
if (!empty($error)) {
|
||||
throw new Exception('Executor Communication Error: ' . $error, 500);
|
||||
}
|
||||
|
||||
// Check status code
|
||||
$statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if (200 !== $statusCode) {
|
||||
throw new Exception('Executor error: ' . $executorResponse, $statusCode);
|
||||
}
|
||||
|
||||
\curl_close($ch);
|
||||
|
||||
$response->noContent();
|
||||
});
|
|
@ -92,6 +92,9 @@ const DATABASE_TYPE_CREATE_ATTRIBUTE = 'createAttribute';
|
|||
const DATABASE_TYPE_CREATE_INDEX = 'createIndex';
|
||||
const DATABASE_TYPE_DELETE_ATTRIBUTE = 'deleteAttribute';
|
||||
const DATABASE_TYPE_DELETE_INDEX = 'deleteIndex';
|
||||
// Build Worker Types
|
||||
const BUILD_TYPE_TAG = 'tag';
|
||||
const BUILD_TYPE_RETRY = 'retry';
|
||||
// Deletion Types
|
||||
const DELETE_TYPE_DOCUMENT = 'document';
|
||||
const DELETE_TYPE_COLLECTIONS = 'collections';
|
||||
|
|
|
@ -15,7 +15,7 @@ Console::title('Builds V1 Worker');
|
|||
Console::success(APP_NAME.' build worker v1 has started');
|
||||
|
||||
class BuildsV1 extends Worker
|
||||
{
|
||||
{
|
||||
|
||||
public function getName(): string {
|
||||
return "builds";
|
||||
|
@ -32,14 +32,21 @@ class BuildsV1 extends Worker
|
|||
$projectId = $this->args['projectId'] ?? '';
|
||||
|
||||
switch ($type) {
|
||||
case 'tag':
|
||||
case BUILD_TYPE_TAG:
|
||||
$functionId = $this->args['functionId'] ?? '';
|
||||
$tagId = $this->args['tagId'] ?? '';
|
||||
Console::success("Creating build for tag: $tagId");
|
||||
$this->buildTag($projectId, $functionId, $tagId);
|
||||
break;
|
||||
|
||||
case BUILD_TYPE_RETRY:
|
||||
$buildId = $this->args['buildId'] ?? '';
|
||||
Console::success("Retrying build for id: $buildId");
|
||||
$this->triggerBuildStage($projectId, $buildId,);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \Exception('Invalid trigger');
|
||||
throw new \Exception('Invalid build type');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +236,9 @@ class BuildsV1 extends Worker
|
|||
$function
|
||||
->setAttribute('tag', $tag->getId())
|
||||
->setAttribute('scheduleNext', (int)$next);
|
||||
$function = $dbForProject->updateDocument('functions', $function->getId(), $function);
|
||||
|
||||
// TODO: Why should we disable auth ?
|
||||
$function = Authorization::skip(fn() => $dbForProject->updateDocument('functions', $functionId, $function));
|
||||
}
|
||||
|
||||
// Deploy Runtime Server
|
||||
|
|
Loading…
Reference in a new issue