1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Stream response support

This commit is contained in:
Matej Bačo 2023-02-15 09:36:20 +01:00
parent 11580a8a69
commit f6ae0a05fa
6 changed files with 20 additions and 14 deletions

2
.env
View file

@ -1,6 +1,6 @@
_APP_ENV=development _APP_ENV=development
_APP_LOCALE=en _APP_LOCALE=en
_APP_WORKER_PER_CORE=2 _APP_WORKER_PER_CORE=20
_APP_CONSOLE_WHITELIST_ROOT=disabled _APP_CONSOLE_WHITELIST_ROOT=disabled
_APP_CONSOLE_WHITELIST_EMAILS= _APP_CONSOLE_WHITELIST_EMAILS=
_APP_CONSOLE_WHITELIST_CODES=code-zero,code-one _APP_CONSOLE_WHITELIST_CODES=code-zero,code-one

View file

@ -1237,8 +1237,8 @@ App::post('/v1/functions/:functionId/executions')
$execution $execution
->setAttribute('duration', (float)$interval->format('%s.%f')) ->setAttribute('duration', (float)$interval->format('%s.%f'))
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('statusCode', $th->getCode()) ->setAttribute('statusCode', 500)
->setAttribute('errors', $th->getMessage()); ->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
Console::error($th->getMessage()); Console::error($th->getMessage());
} }

View file

@ -132,12 +132,16 @@ App::init()
$execution = \json_decode($executionResponse, true); $execution = \json_decode($executionResponse, true);
foreach ($execution['headers'] as $header => $value) { foreach ($execution['headers'] as $header => $value) {
if($header !== "content-length") { $response->setHeader($header, $value);
$response->setHeader($header, $value);
}
} }
return $response->setStatusCode($execution['statusCode'] ?? 200)->send($execution['body'] ?? ''); $body = $execution['body'] ?? '';
if($execution['headers']['x-open-runtimes-encoding'] === 'base64') {
$body = \base64_decode($body);
}
return $response->setStatusCode($execution['statusCode'] ?? 200)->send($body);
} else if(\count($subdomains) === 3) { } else if(\count($subdomains) === 3) {
// Deployment preview // Deployment preview
$deploymentId = $subdomains[0]; $deploymentId = $subdomains[0];

View file

@ -162,8 +162,8 @@ Server::setResource('execute', function () {
$execution $execution
->setAttribute('duration', (float)$interval->format('%s.%f')) ->setAttribute('duration', (float)$interval->format('%s.%f'))
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('statusCode', $th->getCode()) ->setAttribute('statusCode', 500)
->setAttribute('errors', $th->getMessage()); ->setAttribute('errors', $th->getMessage() . '\nError Code: ' . $th->getCode());
Console::error($th->getTraceAsString()); Console::error($th->getTraceAsString());
Console::error($th->getFile()); Console::error($th->getFile());

View file

@ -58,7 +58,7 @@ class Execution extends Model
'type' => self::TYPE_INTEGER, 'type' => self::TYPE_INTEGER,
'description' => 'The script status code.', 'description' => 'The script status code.',
'default' => 0, 'default' => 0,
'example' => 0, 'example' => 200,
]) ])
->addRule('body', [ ->addRule('body', [
'type' => self::TYPE_STRING, 'type' => self::TYPE_STRING,

View file

@ -74,7 +74,6 @@ class Executor
) { ) {
$runtimeId = "$projectId-$deploymentId"; $runtimeId = "$projectId-$deploymentId";
$route = "/runtimes"; $route = "/runtimes";
$reqHeaders = [ 'x-opr-runtime-id' => $runtimeId ];
$params = [ $params = [
'runtimeId' => $runtimeId, 'runtimeId' => $runtimeId,
'source' => $source, 'source' => $source,
@ -92,7 +91,7 @@ class Executor
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
$response = $this->call(self::METHOD_POST, $route, $reqHeaders, $params, true, $timeout); $response = $this->call(self::METHOD_POST, $route, [], $params, true, $timeout);
$status = $response['headers']['status-code']; $status = $response['headers']['status-code'];
if ($status >= 400) { if ($status >= 400) {
@ -133,7 +132,6 @@ class Executor
) { ) {
$runtimeId = "$projectId-$deploymentId"; $runtimeId = "$projectId-$deploymentId";
$route = '/runtimes/' . $runtimeId . '/execution'; $route = '/runtimes/' . $runtimeId . '/execution';
$reqHeaders = [ 'x-opr-runtime-id' => $runtimeId ];
$params = [ $params = [
'runtimeId' => $runtimeId, 'runtimeId' => $runtimeId,
'variables' => $variables, 'variables' => $variables,
@ -153,7 +151,7 @@ class Executor
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
$response = $this->call(self::METHOD_POST, $route, $reqHeaders, $params, true, $timeout); $response = $this->call(self::METHOD_POST, $route, [], $params, true, $timeout);
$status = $response['headers']['status-code']; $status = $response['headers']['status-code'];
if ($status >= 400) { if ($status >= 400) {
@ -238,6 +236,10 @@ class Executor
$responseType = $responseHeaders['content-type'] ?? ''; $responseType = $responseHeaders['content-type'] ?? '';
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
\var_dump($responseBody);
\var_dump($responseStatus);
\var_dump($responseHeaders);
if ($decode) { if ($decode) {
switch (substr($responseType, 0, strpos($responseType, ';'))) { switch (substr($responseType, 0, strpos($responseType, ';'))) {
case 'application/json': case 'application/json':