1
0
Fork 0
mirror of synced 2024-05-21 05:02:37 +12:00

Added tagId to execution log

This commit is contained in:
Eldad Fux 2020-07-18 16:49:20 +03:00
parent 3c2f6d0f28
commit 03e97c68f2
3 changed files with 16 additions and 5 deletions

View file

@ -1377,6 +1377,15 @@ $collections = [
'required' => false,
'array' => false,
],
[
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'label' => 'Tag ID',
'key' => 'tagId',
'type' => Database::SYSTEM_VAR_TYPE_KEY,
'default' => '',
'required' => false,
'array' => false,
],
[
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'label' => 'Status',

View file

@ -68,8 +68,6 @@ $events = array_keys($this->getParam('events', []));
</div>
</div>
<h3>Tags</h3>
<div class="margin-bottom"
data-service="functions.listTags"
data-scope="sdk"
@ -80,6 +78,8 @@ $events = array_keys($this->getParam('events', []));
data-success="trigger"
data-success-param-trigger-events="functions.listTags">
<h3>Tags &nbsp; <span class="text-fade text-size-small pull-end margin-top-small" data-ls-bind="{{project-function-tags.sum}} tags available"></span></h3>
<div data-ls-if="0 == {{project-function-tags.tags.length}} || undefined == {{project-function-tags.tags.length}}" class="box margin-top margin-bottom">
<h3 class="margin-bottom-small text-bold">No Tags Found</h3>

View file

@ -184,6 +184,7 @@ class FunctionsV1
$tagPathTarget = '/tmp/project-'.$projectId.'/'.$tag->getId().'/code.tar.gz';
$tagPathTargetDir = \pathinfo($tagPathTarget, PATHINFO_DIRNAME);
$container = 'appwrite-function-'.$tag->getId();
$command = escapeshellcmd($tag->getAttribute('command', ''));
if(!\is_readable($tagPath)) {
throw new Exception('Code is not readable: '.$tag->getAttribute('codePath', ''));
@ -295,7 +296,7 @@ class FunctionsV1
$executionStart = \microtime(true);
$exitCode = Console::execute("docker exec {$container} sh -c '{$tag->getAttribute('command', '')}'"
$exitCode = Console::execute("docker exec {$container} {$command}"
, null, $stdout, $stderr, $function->getAttribute('timeout', 900)); // TODO add app env for max timeout
$executionEnd = \microtime(true);
@ -305,10 +306,11 @@ class FunctionsV1
Authorization::disable();
$execution = $projectDB->updateDocument(array_merge($execution->getArrayCopy(), [
'tagId' => $tag->getId(),
'status' => ($exitCode === 0) ? 'completed' : 'failed',
'exitCode' => $exitCode,
'stdout' => mb_substr($stdout, -2000), // log last 2000 chars output
'stderr' => mb_substr($stderr, -2000), // log last 2000 chars output
'stdout' => mb_substr($stdout, -4000), // log last 4000 chars output
'stderr' => mb_substr($stderr, -4000), // log last 4000 chars output
'time' => ($executionEnd - $executionStart),
]));