diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 237cf61a7..219097754 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -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', '')); diff --git a/app/workers/builds.php b/app/workers/builds.php index 41f3228d9..440959aeb 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -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 {} diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 1504319cb..474ad92cb 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -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'];