mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 01:18:37 +00:00
Create failed execution if deployment doesn't exist
This commit is contained in:
parent
3d53249335
commit
eb8543c690
1 changed files with 52 additions and 6 deletions
|
|
@ -194,6 +194,51 @@ class Functions extends Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Document $function
|
||||||
|
* @param string $trigger
|
||||||
|
* @param string $path
|
||||||
|
* @param string $method
|
||||||
|
* @param Document $user
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function fail(
|
||||||
|
Database $dbForProject,
|
||||||
|
Document $function,
|
||||||
|
string $trigger,
|
||||||
|
string $path,
|
||||||
|
string $method,
|
||||||
|
Document $user,
|
||||||
|
): void {
|
||||||
|
$executionId = ID::unique();
|
||||||
|
$execution = new Document([
|
||||||
|
'$id' => $executionId,
|
||||||
|
'$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))],
|
||||||
|
'functionInternalId' => $function->getInternalId(),
|
||||||
|
'functionId' => $function->getId(),
|
||||||
|
'deploymentInternalId' => '',
|
||||||
|
'deploymentId' => '',
|
||||||
|
'trigger' => $trigger,
|
||||||
|
'status' => 'failed',
|
||||||
|
'responseStatusCode' => 400,
|
||||||
|
'responseHeaders' => [],
|
||||||
|
'requestPath' => $path,
|
||||||
|
'requestMethod' => $method,
|
||||||
|
'errors' => 'Deployment not found. Create deployment before trying to execute a function.',
|
||||||
|
'logs' => '',
|
||||||
|
'duration' => 0.0,
|
||||||
|
'search' => implode(' ', [$function->getId(), $executionId]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($function->getAttribute('logging')) {
|
||||||
|
$execution = $dbForProject->createDocument('executions', $execution);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($execution->isEmpty()) {
|
||||||
|
throw new Exception('Failed to create execution');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @param Database $dbForProject
|
* @param Database $dbForProject
|
||||||
|
|
@ -248,15 +293,17 @@ class Functions extends Action
|
||||||
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
||||||
|
|
||||||
if ($deployment->getAttribute('resourceId') !== $functionId) {
|
if ($deployment->getAttribute('resourceId') !== $functionId) {
|
||||||
throw new Exception('Deployment not found. Create deployment before trying to execute a function');
|
$this->fail($dbForProject, $function, $trigger, $path, $method, $user);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($deployment->isEmpty()) {
|
if ($deployment->isEmpty()) {
|
||||||
throw new Exception('Deployment not found. Create deployment before trying to execute a function');
|
$this->fail($dbForProject, $function, $trigger, $path, $method, $user);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if build has exists */
|
/** Check if the build exists */
|
||||||
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
|
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
|
||||||
if ($build->isEmpty()) {
|
if ($build->isEmpty()) {
|
||||||
throw new Exception('Build not found');
|
throw new Exception('Build not found');
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +312,7 @@ class Functions extends Action
|
||||||
throw new Exception('Build not ready');
|
throw new Exception('Build not ready');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if runtime is supported */
|
/** Check if runtime is supported */
|
||||||
$version = $function->getAttribute('version', 'v2');
|
$version = $function->getAttribute('version', 'v2');
|
||||||
$runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
|
$runtimes = Config::getParam($version === 'v2' ? 'runtimes-v2' : 'runtimes', []);
|
||||||
|
|
||||||
|
|
@ -280,7 +327,6 @@ class Functions extends Action
|
||||||
$headers['x-appwrite-user-id'] = $user->getId() ?? '';
|
$headers['x-appwrite-user-id'] = $user->getId() ?? '';
|
||||||
$headers['x-appwrite-user-jwt'] = $jwt ?? '';
|
$headers['x-appwrite-user-jwt'] = $jwt ?? '';
|
||||||
|
|
||||||
/** Create execution or update execution status */
|
|
||||||
/** Create execution or update execution status */
|
/** Create execution or update execution status */
|
||||||
$execution = $dbForProject->getDocument('executions', $executionId ?? '');
|
$execution = $dbForProject->getDocument('executions', $executionId ?? '');
|
||||||
if ($execution->isEmpty()) {
|
if ($execution->isEmpty()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue