1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00

Merge pull request #3245 from appwrite/fix-functions-schedule-execution

fix: scheduled functions execution
This commit is contained in:
Torsten Dittmann 2022-05-18 17:06:50 +02:00 committed by GitHub
commit 1961569006
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -94,6 +94,7 @@ class FunctionsV1 extends Worker
$user = new Document($this->args['user'] ?? []);
$project = new Document($this->args['project'] ?? []);
$execution = new Document($this->args['execution'] ?? []);
$function = new Document($this->args['function'] ?? []);
switch ($type) {
case 'http':
@ -117,8 +118,6 @@ class FunctionsV1 extends Worker
case 'schedule':
$scheduleOriginal = $execution->getAttribute('scheduleOriginal', '');
$function = Authorization::skip(fn () => $database->getDocument('functions', $execution->getAttribute('functionId')));
/*
* 1. Get Original Task
* 2. Check for updates
@ -133,6 +132,8 @@ class FunctionsV1 extends Worker
*/
// Reschedule
$function = Authorization::skip(fn () => $database->getDocument('functions', $function->getId()));
if (empty($function->getId())) {
throw new Exception('Function not found (' . $function->getId() . ')');
}
@ -192,6 +193,7 @@ class FunctionsV1 extends Worker
string $jwt = null
) {
$user ??= new Document();
$functionId = $function->getId();
$deploymentId = $function->getAttribute('deployment', '');
@ -227,12 +229,12 @@ class FunctionsV1 extends Worker
/** Create execution or update execution status */
$execution = Authorization::skip(function () use ($dbForProject, &$executionId, $functionId, $deploymentId, $trigger, $user) {
$execution = $dbForProject->getDocument('executions', $executionId);
$execution = $dbForProject->getDocument('executions', $executionId ?? '');
if ($execution->isEmpty()) {
$executionId = $dbForProject->getId();
$execution = $dbForProject->createDocument('executions', new Document([
'$id' => $executionId,
'$read' => $user->getId() ? ['user:' . $user->getId()] : [],
'$read' => $user->isEmpty() ? [] : ['user:' . $user->getId()],
'$write' => [],
'dateCreated' => time(),
'functionId' => $functionId,
@ -281,7 +283,7 @@ class FunctionsV1 extends Worker
path: $build->getAttribute('outputPath', ''),
vars: $vars,
entrypoint: $deployment->getAttribute('entrypoint', ''),
data: $vars['APPWRITE_FUNCTION_DATA'],
data: $vars['APPWRITE_FUNCTION_DATA'] ?? '',
runtime: $function->getAttribute('runtime', ''),
timeout: $function->getAttribute('timeout', 0),
baseImage: $runtime['image']