Implement Suggestions
This commit is contained in:
parent
5080160f09
commit
44ac60a70a
|
@ -16,7 +16,7 @@ use Utopia\Config\Config;
|
||||||
use Utopia\Orchestration\Orchestration;
|
use Utopia\Orchestration\Orchestration;
|
||||||
use Utopia\Orchestration\Adapter\DockerAPI;
|
use Utopia\Orchestration\Adapter\DockerAPI;
|
||||||
use Utopia\Orchestration\Container;
|
use Utopia\Orchestration\Container;
|
||||||
use Utopia\Orchestration\Exceptions\TimeoutException;
|
use Utopia\Orchestration\Exception\Timeout as TimeoutException;
|
||||||
|
|
||||||
require_once __DIR__.'/../workers.php';
|
require_once __DIR__.'/../workers.php';
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ $runtimes = Config::getParam('runtimes');
|
||||||
|
|
||||||
$dockerUser = App::getEnv('DOCKERHUB_PULL_USERNAME', null);
|
$dockerUser = App::getEnv('DOCKERHUB_PULL_USERNAME', null);
|
||||||
$dockerPass = App::getEnv('DOCKERHUB_PULL_PASSWORD', null);
|
$dockerPass = App::getEnv('DOCKERHUB_PULL_PASSWORD', null);
|
||||||
$orchestration = new Orchestration(new DockerAPI($dockerUser, $dockerPass));
|
$dockerEmail = App::getEnv('DOCKERHUB_PULL_EMAIL', null);
|
||||||
|
$orchestration = new Orchestration(new DockerAPI($dockerUser, $dockerPass, $dockerEmail));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warmup Docker Images
|
* Warmup Docker Images
|
||||||
|
@ -40,11 +41,13 @@ Co\run(function() use ($runtimes, $orchestration) { // Warmup: make sure images
|
||||||
foreach($runtimes as $runtime) {
|
foreach($runtimes as $runtime) {
|
||||||
go(function() use ($runtime, $orchestration) {
|
go(function() use ($runtime, $orchestration) {
|
||||||
Console::info('Warming up '.$runtime['name'].' '.$runtime['version'].' environment...');
|
Console::info('Warming up '.$runtime['name'].' '.$runtime['version'].' environment...');
|
||||||
try {
|
|
||||||
$orchestration->pull($runtime['image']);
|
$response = $orchestration->pull($runtime['image']);
|
||||||
|
|
||||||
|
if ($response) {
|
||||||
Console::success("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
|
Console::success("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
|
||||||
} catch (Exception $e) {
|
} else {
|
||||||
Console::error($e);
|
Console::error("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,7 +70,7 @@ $response = $orchestration->list(['label' => 'appwrite-type=function']);
|
||||||
|
|
||||||
$list = [];
|
$list = [];
|
||||||
|
|
||||||
foreach ($response as &$value) {
|
foreach ($response as $value) {
|
||||||
$list[$value->getName()] = $value;
|
$list[$value->getName()] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,13 +371,10 @@ class FunctionsV1 extends Worker
|
||||||
|
|
||||||
$executionStart = \microtime(true);
|
$executionStart = \microtime(true);
|
||||||
$executionTime = \time();
|
$executionTime = \time();
|
||||||
$cpus = App::getEnv('_APP_FUNCTIONS_CPUS', '');
|
|
||||||
$memory = App::getEnv('_APP_FUNCTIONS_MEMORY', '');
|
|
||||||
$swap = App::getEnv('_APP_FUNCTIONS_MEMORY_SWAP', '');
|
|
||||||
|
|
||||||
$orchestration->setCpus($cpus);
|
$orchestration->setCpus(App::getEnv('_APP_FUNCTIONS_CPUS', ''));
|
||||||
$orchestration->setMemory($memory);
|
$orchestration->setMemory(App::getEnv('_APP_FUNCTIONS_MEMORY', ''));
|
||||||
$orchestration->setSwap($swap);
|
$orchestration->setSwap(App::getEnv('_APP_FUNCTIONS_MEMORY_SWAP', ''));
|
||||||
|
|
||||||
foreach($vars as &$value) {
|
foreach($vars as &$value) {
|
||||||
$value = strval($value);
|
$value = strval($value);
|
||||||
|
@ -397,8 +397,8 @@ class FunctionsV1 extends Worker
|
||||||
'appwrite-created' => strval($executionTime)
|
'appwrite-created' => strval($executionTime)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$tarStdout = '';
|
$untarStdout = '';
|
||||||
$tarStderr = '';
|
$untarStderr = '';
|
||||||
|
|
||||||
$untarSuccess = $orchestration->execute(
|
$untarSuccess = $orchestration->execute(
|
||||||
name: $container,
|
name: $container,
|
||||||
|
@ -407,20 +407,18 @@ class FunctionsV1 extends Worker
|
||||||
'-c',
|
'-c',
|
||||||
'mv /tmp/code.tar.gz /usr/local/src/code.tar.gz && tar -zxf /usr/local/src/code.tar.gz --strip 1 && rm /usr/local/src/code.tar.gz'
|
'mv /tmp/code.tar.gz /usr/local/src/code.tar.gz && tar -zxf /usr/local/src/code.tar.gz --strip 1 && rm /usr/local/src/code.tar.gz'
|
||||||
],
|
],
|
||||||
stdout: $tarStdout,
|
stdout: $untarStdout,
|
||||||
stderr: $tarStderr,
|
stderr: $untarStderr,
|
||||||
vars: $vars,
|
vars: $vars,
|
||||||
timeout: 60);
|
timeout: 60);
|
||||||
|
|
||||||
if (!$untarSuccess) {
|
if (!$untarSuccess) {
|
||||||
throw new Exception('Failed to extract tar: '.$stderr);
|
throw new Exception('Failed to extract tar: '.$untarStderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
$executionEnd = \microtime(true);
|
$executionEnd = \microtime(true);
|
||||||
|
|
||||||
$list[$container] = new Container($container,
|
$list[$container] = new Container($container, $id, 'Up',
|
||||||
$id,
|
|
||||||
'Up',
|
|
||||||
[
|
[
|
||||||
'appwrite-type' => 'function',
|
'appwrite-type' => 'function',
|
||||||
'appwrite-created' => strval($executionTime),
|
'appwrite-created' => strval($executionTime),
|
||||||
|
@ -462,7 +460,7 @@ class FunctionsV1 extends Worker
|
||||||
$execution = $database->updateDocument(array_merge($execution->getArrayCopy(), [
|
$execution = $database->updateDocument(array_merge($execution->getArrayCopy(), [
|
||||||
'tagId' => $tag->getId(),
|
'tagId' => $tag->getId(),
|
||||||
'status' => $functionStatus,
|
'status' => $functionStatus,
|
||||||
'exitCode' => ($exitCode === 0 ? 0 : 1),
|
'exitCode' => $exitCode,
|
||||||
'stdout' => \mb_substr($stdout, -4000), // log last 4000 chars output
|
'stdout' => \mb_substr($stdout, -4000), // log last 4000 chars output
|
||||||
'stderr' => \mb_substr($stderr, -4000), // log last 4000 chars output
|
'stderr' => \mb_substr($stderr, -4000), // log last 4000 chars output
|
||||||
'time' => $executionTime
|
'time' => $executionTime
|
||||||
|
|
8
composer.lock
generated
8
composer.lock
generated
|
@ -1913,12 +1913,12 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/PineappleIOnic/orchestration.git",
|
"url": "https://github.com/PineappleIOnic/orchestration.git",
|
||||||
"reference": "213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea"
|
"reference": "e888d0ae03fdaad38b37631cc8a7d75ac0d6c692"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/PineappleIOnic/orchestration/zipball/213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea",
|
"url": "https://api.github.com/repos/PineappleIOnic/orchestration/zipball/e888d0ae03fdaad38b37631cc8a7d75ac0d6c692",
|
||||||
"reference": "213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea",
|
"reference": "e888d0ae03fdaad38b37631cc8a7d75ac0d6c692",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1963,7 +1963,7 @@
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/PineappleIOnic/orchestration/tree/dev"
|
"source": "https://github.com/PineappleIOnic/orchestration/tree/dev"
|
||||||
},
|
},
|
||||||
"time": "2021-08-11T12:45:16+00:00"
|
"time": "2021-08-13T08:34:33+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/preloader",
|
"name": "utopia-php/preloader",
|
||||||
|
|
|
@ -518,7 +518,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||||
$this->assertEquals($executions['body']['executions'][0]['status'], 'failed');
|
$this->assertEquals($executions['body']['executions'][0]['status'], 'failed');
|
||||||
$this->assertEquals($executions['body']['executions'][0]['exitCode'], 1);
|
$this->assertEquals($executions['body']['executions'][0]['exitCode'], 124);
|
||||||
$this->assertGreaterThan(2, $executions['body']['executions'][0]['time']);
|
$this->assertGreaterThan(2, $executions['body']['executions'][0]['time']);
|
||||||
$this->assertLessThan(3, $executions['body']['executions'][0]['time']);
|
$this->assertLessThan(3, $executions['body']['executions'][0]['time']);
|
||||||
$this->assertEquals($executions['body']['executions'][0]['stdout'], '');
|
$this->assertEquals($executions['body']['executions'][0]['stdout'], '');
|
||||||
|
|
Loading…
Reference in a new issue