Add Runtime state tracking using a Swoole table
This commit is contained in:
parent
540738101f
commit
6b228bf57b
1 changed files with 20 additions and 1 deletions
|
@ -4,7 +4,7 @@ namespace Executor;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
use Utopia\CLI\Console;
|
use Swoole\Table;
|
||||||
|
|
||||||
class Executor
|
class Executor
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@ class Executor
|
||||||
const METHOD_TRACE = 'TRACE';
|
const METHOD_TRACE = 'TRACE';
|
||||||
|
|
||||||
private $endpoint;
|
private $endpoint;
|
||||||
|
private $runtimeQueue;
|
||||||
|
|
||||||
private $selfSigned = false;
|
private $selfSigned = false;
|
||||||
|
|
||||||
|
@ -32,6 +33,9 @@ class Executor
|
||||||
throw new Exception('Unsupported endpoint');
|
throw new Exception('Unsupported endpoint');
|
||||||
}
|
}
|
||||||
$this->endpoint = $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
|
'commands' => $commands
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$this->runtimeQueue->set($params['runtimeId'], [
|
||||||
|
'id' => $params['runtimeId'],
|
||||||
|
'state' => 'pending'
|
||||||
|
]);
|
||||||
|
|
||||||
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
|
$timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900);
|
||||||
|
|
||||||
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $timeout);
|
$response = $this->call(self::METHOD_POST, $route, $headers, $params, true, $timeout);
|
||||||
|
@ -174,6 +183,16 @@ class Executor
|
||||||
case $status < 400:
|
case $status < 400:
|
||||||
return $response['body'];
|
return $response['body'];
|
||||||
case $status === 404:
|
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(
|
$response = $this->createRuntime(
|
||||||
deploymentId: $deploymentId,
|
deploymentId: $deploymentId,
|
||||||
projectId: $projectId,
|
projectId: $projectId,
|
||||||
|
|
Loading…
Reference in a new issue