From 391d1127caedcf1f27c5bed53110ef109e36c8ec Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 10 Aug 2022 07:19:07 +0000 Subject: [PATCH] update container to accept new response format --- app/config/collections.php | 11 +++++++++++ app/controllers/api/functions.php | 1 + app/executor.php | 13 +++++++++---- app/workers/functions.php | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index ecbe92c333..f1ea8fed95 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -2386,6 +2386,17 @@ $collections = [ 'array' => false, 'filters' => [], ], + [ + '$id' => 'stdout', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 1000000, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'statusCode', 'type' => Database::VAR_INTEGER, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 21b827042d..bc0edc02da 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -945,6 +945,7 @@ App::post('/v1/functions/:functionId/executions') $execution->setAttribute('status', $executionResponse['status']); $execution->setAttribute('statusCode', $executionResponse['statusCode']); $execution->setAttribute('response', $executionResponse['response']); + $execution->setAttribute('stdout', $executionResponse['stdout']); $execution->setAttribute('stderr', $executionResponse['stderr']); $execution->setAttribute('time', $executionResponse['time']); } catch (\Throwable $th) { diff --git a/app/executor.php b/app/executor.php index 22d8552635..8d4bf9a001 100644 --- a/app/executor.php +++ b/app/executor.php @@ -488,6 +488,7 @@ App::post('/v1/execution') $executionStart = \microtime(true); $stdout = ''; $stderr = ''; + $res = ''; $statusCode = 0; $errNo = -1; $executorResponse = ''; @@ -538,13 +539,16 @@ App::post('/v1/execution') switch (true) { case $statusCode >= 500: - $stderr = $executorResponse ?? 'Internal Runtime error.'; + $stderr = ($executorResponse ?? [])['stderr'] ?? 'Internal Runtime error.'; + $stdout = ($executorResponse ?? [])['stdout'] ?? 'Internal Runtime error.'; break; case $statusCode >= 100: - $stdout = $executorResponse; + $stdout = $executorResponse['stdout']; + $res = $executorResponse['response']; break; default: - $stderr = $executorResponse ?? 'Execution failed.'; + $stderr = ($executorResponse ?? [])['stderr'] ?? 'Execution failed.'; + $stdout = ($executorResponse ?? [])['stdout'] ?? ''; break; } @@ -557,7 +561,8 @@ App::post('/v1/execution') $execution = [ 'status' => $functionStatus, 'statusCode' => $statusCode, - 'response' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB + 'response' => \mb_strcut($res, 0, 1000000), // Limit to 1MB + 'stdout' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB 'stderr' => \mb_strcut($stderr, 0, 1000000), // Limit to 1MB 'time' => $executionTime, ]; diff --git a/app/workers/functions.php b/app/workers/functions.php index 55d71ef368..8c0716665a 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -293,6 +293,7 @@ class FunctionsV1 extends Worker ->setAttribute('status', $executionResponse['status']) ->setAttribute('statusCode', $executionResponse['statusCode']) ->setAttribute('response', $executionResponse['response']) + ->setAttribute('stdout', $executionResponse['stdout']) ->setAttribute('stderr', $executionResponse['stderr']) ->setAttribute('time', $executionResponse['time']); } catch (\Throwable $th) {