feat: fix executor issues
This commit is contained in:
parent
6610bf9873
commit
f83fdc92de
3 changed files with 21 additions and 36 deletions
|
@ -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);
|
|
||||||
\curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
|
|
||||||
'deploymentId' => $deployment->getId(),
|
|
||||||
'buildId' => $deployment->getAttribute('buildId', ''),
|
|
||||||
'path' => $build->getAttribute('outputPath', ''),
|
|
||||||
'vars' => $vars,
|
|
||||||
'data' => $data,
|
|
||||||
'runtime' => $function->getAttribute('runtime', ''),
|
|
||||||
'timeout' => $function->getAttribute('timeout', 0),
|
|
||||||
'baseImage' => $runtime['image'],
|
|
||||||
'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);
|
$responseExecute = $executor->createExecution(
|
||||||
|
projectId: $project->getId(),
|
||||||
|
functionId: $function->getId(),
|
||||||
|
deploymentId: $deployment->getId(),
|
||||||
|
buildId: $deployment->getAttribute('buildId', ''),
|
||||||
|
path: $build->getAttribute('outputPath', ''),
|
||||||
|
vars: $vars,
|
||||||
|
data: $data,
|
||||||
|
runtime: $function->getAttribute('runtime', ''),
|
||||||
|
timeout: $function->getAttribute('timeout', 0),
|
||||||
|
baseImage: $runtime['image'],
|
||||||
|
webhooks: $project->getAttribute('webhooks', []),
|
||||||
|
userId: $user->getId(),
|
||||||
|
);
|
||||||
|
|
||||||
$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']);
|
||||||
|
|
|
@ -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', '')
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue