1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00

feat: fix executor issues

This commit is contained in:
Christy Jacob 2022-02-05 14:08:05 +04:00
parent 6610bf9873
commit f83fdc92de
3 changed files with 21 additions and 36 deletions

View file

@ -25,6 +25,7 @@ use Utopia\Validator\Range;
use Utopia\Validator\WhiteList; use Utopia\Validator\WhiteList;
use Utopia\Config\Config; use Utopia\Config\Config;
use Cron\CronExpression; use Cron\CronExpression;
use Executor\Executor;
use Utopia\CLI\Console; use Utopia\CLI\Console;
use Utopia\Validator\Boolean; use Utopia\Validator\Boolean;
@ -865,45 +866,29 @@ App::post('/v1/functions/:functionId/executions')
'APPWRITE_FUNCTION_RUNTIME_NAME' => $runtime['name'], 'APPWRITE_FUNCTION_RUNTIME_NAME' => $runtime['name'],
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'], 'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'],
'APPWRITE_FUNCTION_DATA' => $data, 'APPWRITE_FUNCTION_DATA' => $data,
'APPWRITE_FUNCTION_PROJECT_ID' => $project->getId(),
'APPWRITE_FUNCTION_USER_ID' => $user->getId(), 'APPWRITE_FUNCTION_USER_ID' => $user->getId(),
'APPWRITE_FUNCTION_JWT' => $jwt, 'APPWRITE_FUNCTION_JWT' => $jwt,
'APPWRITE_FUNCTION_PROJECT_ID' => $project->getId()
]); ]);
// Directly execute function. // Directly execute function.
$ch = \curl_init(); $executor = new Executor();
\curl_setopt($ch, CURLOPT_URL, "http://appwrite-executor/v1/functions/{$function->getId()}/executions");
\curl_setopt($ch, CURLOPT_POST, true); $responseExecute = $executor->createExecution(
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ projectId: $project->getId(),
'deploymentId' => $deployment->getId(), functionId: $function->getId(),
'buildId' => $deployment->getAttribute('buildId', ''), deploymentId: $deployment->getId(),
'path' => $build->getAttribute('outputPath', ''), buildId: $deployment->getAttribute('buildId', ''),
'vars' => $vars, path: $build->getAttribute('outputPath', ''),
'data' => $data, vars: $vars,
'runtime' => $function->getAttribute('runtime', ''), data: $data,
'timeout' => $function->getAttribute('timeout', 0), runtime: $function->getAttribute('runtime', ''),
'baseImage' => $runtime['image'], timeout: $function->getAttribute('timeout', 0),
'webhooks' => $project->getAttribute('webhooks', []), baseImage: $runtime['image'],
'userId' => $user->getId(), webhooks: $project->getAttribute('webhooks', []),
])); userId: $user->getId(),
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); );
\curl_setopt($ch, CURLOPT_TIMEOUT, App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900) + 200); // + 200 for safety margin
\curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
\curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'x-appwrite-project: '.$project->getId(),
'x-appwrite-executor-key: '. App::getEnv('_APP_EXECUTOR_SECRET', '')
]);
$responseExecute = \curl_exec($ch);
$error = \curl_error($ch);
if (!empty($error)) {
Console::error('Curl error: '.$error);
}
\curl_close($ch);
$responseExecute = json_decode($responseExecute, true);
$execution->setAttribute('status', $responseExecute['status']); $execution->setAttribute('status', $responseExecute['status']);
$execution->setAttribute('statusCode', $responseExecute['statusCode']); $execution->setAttribute('statusCode', $responseExecute['statusCode']);
$execution->setAttribute('stdout', $responseExecute['stdout']); $execution->setAttribute('stdout', $responseExecute['stdout']);

View file

@ -349,7 +349,7 @@ function execute(string $projectId, string $functionId, string $deploymentId, ar
} }
var_dump($executorResponse); var_dump($executorResponse);
$executionData = []; $executionData = [];
if (!empty($executorResponse)) { if (!empty($executorResponse)) {

View file

@ -67,7 +67,7 @@ class Executor
{ {
$route = "/deployments/$deploymentId"; $route = "/deployments/$deploymentId";
$headers = [ $headers = [
'content-Type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '') 'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '')
]; ];
@ -102,7 +102,7 @@ class Executor
{ {
$route = "/functions/$functionId/executions"; $route = "/functions/$functionId/executions";
$headers = [ $headers = [
'content-Type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $projectId, 'x-appwrite-project' => $projectId,
'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '') 'x-appwrite-executor-key' => App::getEnv('_APP_EXECUTOR_SECRET', '')
]; ];