Implement Suggestions
This commit is contained in:
parent
5080160f09
commit
44ac60a70a
3 changed files with 25 additions and 27 deletions
|
@ -16,7 +16,7 @@ use Utopia\Config\Config;
|
|||
use Utopia\Orchestration\Orchestration;
|
||||
use Utopia\Orchestration\Adapter\DockerAPI;
|
||||
use Utopia\Orchestration\Container;
|
||||
use Utopia\Orchestration\Exceptions\TimeoutException;
|
||||
use Utopia\Orchestration\Exception\Timeout as TimeoutException;
|
||||
|
||||
require_once __DIR__.'/../workers.php';
|
||||
|
||||
|
@ -29,7 +29,8 @@ $runtimes = Config::getParam('runtimes');
|
|||
|
||||
$dockerUser = App::getEnv('DOCKERHUB_PULL_USERNAME', 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
|
||||
|
@ -40,11 +41,13 @@ Co\run(function() use ($runtimes, $orchestration) { // Warmup: make sure images
|
|||
foreach($runtimes as $runtime) {
|
||||
go(function() use ($runtime, $orchestration) {
|
||||
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']}!");
|
||||
} catch (Exception $e) {
|
||||
Console::error($e);
|
||||
} else {
|
||||
Console::error("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -67,7 +70,7 @@ $response = $orchestration->list(['label' => 'appwrite-type=function']);
|
|||
|
||||
$list = [];
|
||||
|
||||
foreach ($response as &$value) {
|
||||
foreach ($response as $value) {
|
||||
$list[$value->getName()] = $value;
|
||||
}
|
||||
|
||||
|
@ -368,13 +371,10 @@ class FunctionsV1 extends Worker
|
|||
|
||||
$executionStart = \microtime(true);
|
||||
$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->setMemory($memory);
|
||||
$orchestration->setSwap($swap);
|
||||
$orchestration->setCpus(App::getEnv('_APP_FUNCTIONS_CPUS', ''));
|
||||
$orchestration->setMemory(App::getEnv('_APP_FUNCTIONS_MEMORY', ''));
|
||||
$orchestration->setSwap(App::getEnv('_APP_FUNCTIONS_MEMORY_SWAP', ''));
|
||||
|
||||
foreach($vars as &$value) {
|
||||
$value = strval($value);
|
||||
|
@ -397,8 +397,8 @@ class FunctionsV1 extends Worker
|
|||
'appwrite-created' => strval($executionTime)
|
||||
]);
|
||||
|
||||
$tarStdout = '';
|
||||
$tarStderr = '';
|
||||
$untarStdout = '';
|
||||
$untarStderr = '';
|
||||
|
||||
$untarSuccess = $orchestration->execute(
|
||||
name: $container,
|
||||
|
@ -407,20 +407,18 @@ class FunctionsV1 extends Worker
|
|||
'-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'
|
||||
],
|
||||
stdout: $tarStdout,
|
||||
stderr: $tarStderr,
|
||||
stdout: $untarStdout,
|
||||
stderr: $untarStderr,
|
||||
vars: $vars,
|
||||
timeout: 60);
|
||||
|
||||
if (!$untarSuccess) {
|
||||
throw new Exception('Failed to extract tar: '.$stderr);
|
||||
throw new Exception('Failed to extract tar: '.$untarStderr);
|
||||
}
|
||||
|
||||
$executionEnd = \microtime(true);
|
||||
|
||||
$list[$container] = new Container($container,
|
||||
$id,
|
||||
'Up',
|
||||
$list[$container] = new Container($container, $id, 'Up',
|
||||
[
|
||||
'appwrite-type' => 'function',
|
||||
'appwrite-created' => strval($executionTime),
|
||||
|
@ -462,7 +460,7 @@ class FunctionsV1 extends Worker
|
|||
$execution = $database->updateDocument(array_merge($execution->getArrayCopy(), [
|
||||
'tagId' => $tag->getId(),
|
||||
'status' => $functionStatus,
|
||||
'exitCode' => ($exitCode === 0 ? 0 : 1),
|
||||
'exitCode' => $exitCode,
|
||||
'stdout' => \mb_substr($stdout, -4000), // log last 4000 chars output
|
||||
'stderr' => \mb_substr($stderr, -4000), // log last 4000 chars output
|
||||
'time' => $executionTime
|
||||
|
|
8
composer.lock
generated
8
composer.lock
generated
|
@ -1913,12 +1913,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PineappleIOnic/orchestration.git",
|
||||
"reference": "213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea"
|
||||
"reference": "e888d0ae03fdaad38b37631cc8a7d75ac0d6c692"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PineappleIOnic/orchestration/zipball/213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea",
|
||||
"reference": "213d8796cd3b4a23b8d3728227b0e8ab1ceb4aea",
|
||||
"url": "https://api.github.com/repos/PineappleIOnic/orchestration/zipball/e888d0ae03fdaad38b37631cc8a7d75ac0d6c692",
|
||||
"reference": "e888d0ae03fdaad38b37631cc8a7d75ac0d6c692",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1963,7 +1963,7 @@
|
|||
"support": {
|
||||
"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",
|
||||
|
|
|
@ -518,7 +518,7 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
|
||||
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
|
||||
$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->assertLessThan(3, $executions['body']['executions'][0]['time']);
|
||||
$this->assertEquals($executions['body']['executions'][0]['stdout'], '');
|
||||
|
|
Loading…
Reference in a new issue