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