1
0
Fork 0
mirror of synced 2024-06-27 02:31:04 +12:00

feat: propogate errors in Executor

This commit is contained in:
Christy Jacob 2022-02-16 15:43:21 +04:00
parent b6758c1262
commit cef5264c48
3 changed files with 22 additions and 21 deletions

View file

@ -617,7 +617,7 @@ App::get('/v1/functions/:functionId/deployments')
$sum = $dbForProject->count('deployments', $queries, APP_LIMIT_COUNT);
foreach ($results as $result) {
$build = $dbForProject->getDocument('builds', $result->getAttribute('buildId'));
$build = $dbForProject->getDocument('builds', $result->getAttribute('buildId', ''));
$result->setAttribute('status', $build->getAttribute('status', 'pending'));
$result->setAttribute('buildStderr', $build->getAttribute('stderr', ''));
$result->setAttribute('buildStdout', $build->getAttribute('stdout', ''));

View file

@ -136,6 +136,22 @@ class BuildsV1 extends Worker
$build->setAttribute('outputPath', $response['outputPath']);
$build->setAttribute('stderr', $response['stderr']);
$build->setAttribute('stdout', $response['stdout']);
Console::success("Build id: $buildId created");
/** Set auto deploy */
if ($deployment->getAttribute('activate') === true) {
$function->setAttribute('deployment', $deployment->getId());
$function = $dbForProject->updateDocument('functions', $functionId, $function);
}
/** Update function schedule */
$schedule = $function->getAttribute('schedule', '');
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$function->setAttribute('scheduleNext', (int)$next);
$function = $dbForProject->updateDocument('functions', $functionId, $function);
} catch (\Throwable $th) {
$endtime = \time();
$build->setAttribute('endTime', $endtime);
@ -143,24 +159,9 @@ class BuildsV1 extends Worker
$build->setAttribute('status', 'failed');
$build->setAttribute('stderr', $th->getMessage());
Console::error($th->getMessage());
} finally {
$build = $dbForProject->updateDocument('builds', $buildId, $build);
}
$build = $dbForProject->updateDocument('builds', $buildId, $build);
/** Set auto deploy */
if ($deployment->getAttribute('activate') === true) {
$function->setAttribute('deployment', $deployment->getId());
$function = $dbForProject->updateDocument('functions', $functionId, $function);
}
/** Update function schedule */
$schedule = $function->getAttribute('schedule', '');
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$function->setAttribute('scheduleNext', (int)$next);
$function = $dbForProject->updateDocument('functions', $functionId, $function);
Console::success("Build id: $buildId created");
}
public function shutdown(): void {}

View file

@ -58,7 +58,7 @@ class Executor
$status = $response['headers']['status-code'];
if ($status >= 400) {
throw new \Exception($response['body'], $status);
throw new \Exception($response['body']['message'], $status);
}
return $response['body'];
@ -80,7 +80,7 @@ class Executor
$status = $response['headers']['status-code'];
if ($status >= 400) {
throw new \Exception('Error deleting deployment: ' . $deploymentId , $status);
throw new \Exception($response['body']['message'], $status);
}
return $response['body'];
@ -120,7 +120,7 @@ class Executor
$status = $response['headers']['status-code'];
if ($status >= 400) {
throw new \Exception('Error creating execution: ', $status);
throw new \Exception($response['body']['message'], $status);
}
return $response['body'];