Merge pull request #3245 from appwrite/fix-functions-schedule-execution
fix: scheduled functions execution
This commit is contained in:
commit
1961569006
1 changed files with 7 additions and 5 deletions
|
@ -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']
|
||||
|
|
Loading…
Reference in a new issue