1
0
Fork 0
mirror of synced 2024-07-12 18:05:55 +12:00

Add Runtime state tracking using a Swoole table

This commit is contained in:
Bradley Schofield 2022-06-06 10:57:23 +01:00
parent 540738101f
commit 6b228bf57b

View file

@ -4,7 +4,7 @@ namespace Executor;
use Exception;
use Utopia\App;
use Utopia\CLI\Console;
use Swoole\Table;
class Executor
{
@ -19,6 +19,7 @@ class Executor
const METHOD_TRACE = 'TRACE';
private $endpoint;
private $runtimeQueue;
private $selfSigned = false;
@ -32,6 +33,9 @@ class Executor
throw new Exception('Unsupported endpoint');
}
$this->endpoint = $endpoint;
$this->runtimeQueue = new Table(1024);
$this->runtimeQueue->column('id', Table::TYPE_STRING, 128);
$this->runtimeQueue->column('state', Table::TYPE_STRING, 128);
}
/**
@ -83,6 +87,11 @@ class Executor
'commands' => $commands
];
$this->runtimeQueue->set($params['runtimeId'], [
'id' => $params['runtimeId'],
'state' => 'pending'
]);
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $timeout);
@ -174,6 +183,16 @@ class Executor
case $status < 400:
return $response['body'];
case $status === 404:
if ($this->runtimeQueue->get($params['runtimeId'])) {
if ($this->runtimeQueue->get($params['runtimeId'])['state'] === 'pending') {
sleep(1);
continue 2;
}
}
$this->runtimeQueue->set($params['runtimeId'], [
'id' => $params['runtimeId'],
'state' => 'pending'
]);
$response = $this->createRuntime(
deploymentId: $deploymentId,
projectId: $projectId,