More Changes
This commit is contained in:
parent
48d57aa38e
commit
f5e1ce01b7
|
@ -355,7 +355,7 @@ App::patch('/v1/functions/:functionId/tag')
|
||||||
/** @var Appwrite\Database\Document $project */
|
/** @var Appwrite\Database\Document $project */
|
||||||
|
|
||||||
$ch = \curl_init();
|
$ch = \curl_init();
|
||||||
\curl_setopt($ch, CURLOPT_URL, "http://executor:8080/v1/tag");
|
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor:8080/v1/tag");
|
||||||
\curl_setopt($ch, CURLOPT_POST, true);
|
\curl_setopt($ch, CURLOPT_POST, true);
|
||||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
||||||
'functionId' => $functionId,
|
'functionId' => $functionId,
|
||||||
|
@ -775,7 +775,7 @@ App::post('/v1/functions/:functionId/executions')
|
||||||
}
|
}
|
||||||
// Directly execute function.
|
// Directly execute function.
|
||||||
$ch = \curl_init();
|
$ch = \curl_init();
|
||||||
\curl_setopt($ch, CURLOPT_URL, "http://executor:8080/v1/execute");
|
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor:8080/v1/execute");
|
||||||
\curl_setopt($ch, CURLOPT_POST, true);
|
\curl_setopt($ch, CURLOPT_POST, true);
|
||||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
||||||
'trigger' => 'http',
|
'trigger' => 'http',
|
||||||
|
|
|
@ -39,21 +39,21 @@ $runtimes = Config::getParam('runtimes');
|
||||||
Swoole\Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_CURL);
|
Swoole\Runtime::enableCoroutine(true, SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_CURL);
|
||||||
|
|
||||||
// Warmup: make sure images are ready to run fast 🚀
|
// Warmup: make sure images are ready to run fast 🚀
|
||||||
Co\run(function() use ($runtimes, $orchestration) {
|
// Co\run(function() use ($runtimes, $orchestration) {
|
||||||
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...');
|
||||||
|
|
||||||
$response = $orchestration->pull($runtime['image']);
|
// $response = $orchestration->pull($runtime['image']);
|
||||||
|
|
||||||
if ($response) {
|
// if ($response) {
|
||||||
Console::success("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
|
// Console::success("Successfully Warmed up {$runtime['name']} {$runtime['version']}!");
|
||||||
} else {
|
// } else {
|
||||||
Console::error("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
|
// Console::error("Failed to Warmup {$runtime['name']} {$runtime['version']}!");
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List function servers
|
* List function servers
|
||||||
|
@ -409,40 +409,60 @@ function execute(string $trigger, string $projectId, string $executionId, string
|
||||||
|
|
||||||
$exitCode = 0;
|
$exitCode = 0;
|
||||||
|
|
||||||
|
$errNo = -1;
|
||||||
|
$attempts = 0;
|
||||||
|
$max = 5;
|
||||||
|
|
||||||
|
$executorResponse = '';
|
||||||
|
|
||||||
// cURL request to runtime
|
// cURL request to runtime
|
||||||
$ch = \curl_init();
|
do {
|
||||||
\curl_setopt($ch, CURLOPT_URL, "http://".$container.":3000/");
|
$attempts++;
|
||||||
\curl_setopt($ch, CURLOPT_POST, true);
|
$ch = \curl_init();
|
||||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
\curl_setopt($ch, CURLOPT_URL, "http://".$container.":3000/");
|
||||||
'path' => '/usr/code',
|
\curl_setopt($ch, CURLOPT_POST, true);
|
||||||
'file' => 'index.js',
|
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
||||||
'env' => $vars,
|
'path' => '/usr/code',
|
||||||
'payload' => $data
|
'file' => 'index.js',
|
||||||
]));
|
'env' => $vars,
|
||||||
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
'payload' => $data
|
||||||
\curl_setopt($ch, CURLOPT_TIMEOUT, $function->getAttribute('timeout', (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)));
|
]));
|
||||||
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
\curl_setopt($ch, CURLOPT_TIMEOUT, $function->getAttribute('timeout', (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)));
|
||||||
|
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
|
|
||||||
$executorResponse = \curl_exec($ch);
|
$executorResponse = \curl_exec($ch);
|
||||||
|
|
||||||
$error = \curl_error($ch);
|
$error = \curl_error($ch);
|
||||||
if (!empty($error)) {
|
|
||||||
|
$errNo = \curl_errno($ch);
|
||||||
|
|
||||||
|
\curl_close($ch);
|
||||||
|
if ($errNo != CURLE_COULDNT_CONNECT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
} while ($attempts < $max);
|
||||||
|
|
||||||
|
if ($attempts >= 5) {
|
||||||
|
$stderr = 'Failed to connect to executor runtime after 5 attempts.';
|
||||||
|
$exitCode = 124;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($errNo !== 0 && $errNo != CURLE_COULDNT_CONNECT) {
|
||||||
throw new Exception('Curl error: ' . $error, 500);
|
throw new Exception('Curl error: ' . $error, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
\curl_close($ch);
|
|
||||||
|
|
||||||
$executionData = json_decode($executorResponse, true);
|
$executionData = json_decode($executorResponse, true);
|
||||||
if (\is_null($executionData)) {
|
|
||||||
throw new Exception('Failed to decode JSON response', 500);
|
|
||||||
}
|
|
||||||
if (isset($executionData['code'])) {
|
if (isset($executionData['code'])) {
|
||||||
$exitCode = $executionData['code'];
|
$exitCode = $executionData['code'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exitCode === 500) {
|
if ($exitCode === 500) {
|
||||||
$stderr = $executionData['message'];
|
$stderr = $executionData['message'];
|
||||||
} else {
|
} else if ($exitCode === 0) {
|
||||||
$stdout = $executorResponse;
|
$stdout = $executorResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,7 @@ class FunctionsV1 extends Worker
|
||||||
public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', array $webhooks = [], string $userId = '', string $jwt = ''): void
|
public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', array $webhooks = [], string $userId = '', string $jwt = ''): void
|
||||||
{
|
{
|
||||||
$ch = \curl_init();
|
$ch = \curl_init();
|
||||||
\curl_setopt($ch, CURLOPT_URL, "http://executor:8080/v1/execute");
|
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor:8080/v1/execute");
|
||||||
\curl_setopt($ch, CURLOPT_POST, true);
|
\curl_setopt($ch, CURLOPT_POST, true);
|
||||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
||||||
'trigger' => $trigger,
|
'trigger' => $trigger,
|
||||||
|
|
|
@ -319,7 +319,6 @@ services:
|
||||||
- -e
|
- -e
|
||||||
- app/executor.php
|
- app/executor.php
|
||||||
- -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
|
- -dopcache.preload=opcache.preload=/usr/src/code/app/preload.php
|
||||||
container_name: appwrite-executor
|
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
build:
|
build:
|
||||||
|
@ -330,8 +329,6 @@ services:
|
||||||
- VERSION=dev
|
- VERSION=dev
|
||||||
networks:
|
networks:
|
||||||
appwrite:
|
appwrite:
|
||||||
aliases:
|
|
||||||
- executor
|
|
||||||
runtimes:
|
runtimes:
|
||||||
volumes:
|
volumes:
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
|
Loading…
Reference in a new issue