fix(functions): utf-8 encode stdout and stderr
This commit is contained in:
parent
7e1a03effd
commit
d2f425e67d
|
@ -482,7 +482,7 @@ class FunctionsV1 extends Worker
|
||||||
$exitCode = 0;
|
$exitCode = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$exitCode = (int)!$orchestration->execute(
|
$exitCode = (int) !$orchestration->execute(
|
||||||
name: $container,
|
name: $container,
|
||||||
command: $orchestration->parseCommandString($command),
|
command: $orchestration->parseCommandString($command),
|
||||||
stdout: $stdout,
|
stdout: $stdout,
|
||||||
|
@ -509,8 +509,8 @@ class FunctionsV1 extends Worker
|
||||||
'tagId' => $tag->getId(),
|
'tagId' => $tag->getId(),
|
||||||
'status' => $functionStatus,
|
'status' => $functionStatus,
|
||||||
'exitCode' => $exitCode,
|
'exitCode' => $exitCode,
|
||||||
'stdout' => \mb_substr($stdout, -4000), // log last 4000 chars output
|
'stdout' => \utf8_encode(\mb_substr($stdout, -4000)), // log last 4000 chars output
|
||||||
'stderr' => \mb_substr($stderr, -4000), // log last 4000 chars output
|
'stderr' => \utf8_encode(\mb_substr($stderr, -4000)), // log last 4000 chars output
|
||||||
'time' => $executionTime
|
'time' => $executionTime
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -535,11 +535,11 @@ class FunctionsV1 extends Worker
|
||||||
$target = Realtime::fromPayload('functions.executions.update', $execution);
|
$target = Realtime::fromPayload('functions.executions.update', $execution);
|
||||||
|
|
||||||
Realtime::send(
|
Realtime::send(
|
||||||
$projectId,
|
projectId: $projectId,
|
||||||
$execution->getArrayCopy(),
|
payload: $execution->getArrayCopy(),
|
||||||
'functions.executions.update',
|
event: 'functions.executions.update',
|
||||||
$target['channels'],
|
channels: $target['channels'],
|
||||||
$target['roles']
|
roles: $target['roles']
|
||||||
);
|
);
|
||||||
|
|
||||||
$usage = new Event('v1-usage', 'UsageV1');
|
$usage = new Event('v1-usage', 'UsageV1');
|
||||||
|
@ -551,8 +551,7 @@ class FunctionsV1 extends Worker
|
||||||
->setParam('functionStatus', $functionStatus)
|
->setParam('functionStatus', $functionStatus)
|
||||||
->setParam('functionExecutionTime', $executionTime * 1000) // ms
|
->setParam('functionExecutionTime', $executionTime * 1000) // ms
|
||||||
->setParam('networkRequestSize', 0)
|
->setParam('networkRequestSize', 0)
|
||||||
->setParam('networkResponseSize', 0)
|
->setParam('networkResponseSize', 0);
|
||||||
;
|
|
||||||
|
|
||||||
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
||||||
$usage->trigger();
|
$usage->trigger();
|
||||||
|
|
|
@ -326,6 +326,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$this->assertStringContainsString('http', $execution['body']['stdout']);
|
$this->assertStringContainsString('http', $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('PHP', $execution['body']['stdout']);
|
$this->assertStringContainsString('PHP', $execution['body']['stdout']);
|
||||||
$this->assertStringContainsString('8.0', $execution['body']['stdout']);
|
$this->assertStringContainsString('8.0', $execution['body']['stdout']);
|
||||||
|
$this->assertStringContainsString('êä', $execution['body']['stdout']); // tests unknown utf-8 chars
|
||||||
$this->assertEquals('', $execution['body']['stderr']);
|
$this->assertEquals('', $execution['body']['stderr']);
|
||||||
$this->assertGreaterThan(0.05, $execution['body']['time']);
|
$this->assertGreaterThan(0.05, $execution['body']['time']);
|
||||||
$this->assertLessThan(0.500, $execution['body']['time']);
|
$this->assertLessThan(0.500, $execution['body']['time']);
|
||||||
|
|
0
tests/resources/functions/package-php.sh
Normal file → Executable file
0
tests/resources/functions/package-php.sh
Normal file → Executable file
Binary file not shown.
|
@ -25,4 +25,6 @@ echo $_ENV['APPWRITE_FUNCTION_RUNTIME_NAME']."\n";
|
||||||
echo $_ENV['APPWRITE_FUNCTION_RUNTIME_VERSION']."\n";
|
echo $_ENV['APPWRITE_FUNCTION_RUNTIME_VERSION']."\n";
|
||||||
// echo $result['$id'];
|
// echo $result['$id'];
|
||||||
echo $_ENV['APPWRITE_FUNCTION_EVENT']."\n";
|
echo $_ENV['APPWRITE_FUNCTION_EVENT']."\n";
|
||||||
echo $_ENV['APPWRITE_FUNCTION_EVENT_DATA']."\n";
|
echo $_ENV['APPWRITE_FUNCTION_EVENT_DATA']."\n";
|
||||||
|
// Test unknwon UTF-8 chars
|
||||||
|
echo "\xEA\xE4\n";
|
Loading…
Reference in a new issue