1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00

scheduleNext + schedulePrevious functions changes

This commit is contained in:
fogelito 2022-07-07 12:26:30 +03:00
parent 05f8352837
commit e0f2d59864
6 changed files with 26 additions and 29 deletions

View file

@ -1971,10 +1971,10 @@ $collections = [
],
[
'$id' => 'schedulePrevious',
'type' => Database::VAR_INTEGER,
'type' => Database::VAR_DATETIME,
'format' => '',
'size' => 0,
'signed' => true,
'signed' => false,
'required' => false,
'default' => null,
'array' => false,
@ -1982,10 +1982,10 @@ $collections = [
],
[
'$id' => 'scheduleNext',
'type' => Database::VAR_INTEGER,
'type' => Database::VAR_DATETIME,
'format' => '',
'size' => 0,
'signed' => true,
'signed' => false,
'required' => false,
'default' => null,
'array' => false,

View file

@ -73,8 +73,8 @@ App::post('/v1/functions')
'vars' => $vars,
'events' => $events,
'schedule' => $schedule,
'schedulePrevious' => 0,
'scheduleNext' => 0,
'schedulePrevious' => null,
'scheduleNext' => null,
'timeout' => $timeout,
'search' => implode(' ', [$functionId, $name, $runtime]),
]));
@ -308,8 +308,8 @@ App::put('/v1/functions/:functionId')
}
$original = $function->getAttribute('schedule', '');
$cron = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (!empty($function->getAttribute('deployment', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$cron = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (!empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null;
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'execute' => $execute,
@ -317,7 +317,7 @@ App::put('/v1/functions/:functionId')
'vars' => $vars,
'events' => $events,
'schedule' => $schedule,
'scheduleNext' => (int)$next,
'scheduleNext' => $next,
'timeout' => $timeout,
'search' => implode(' ', [$functionId, $name, $function->getAttribute('runtime')]),
])));
@ -381,11 +381,11 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId')
$schedule = $function->getAttribute('schedule', '');
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null;
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'deployment' => $deployment->getId(),
'scheduleNext' => (int)$next,
'scheduleNext' => $next,
])));
if ($next) { // Init first schedule

View file

@ -6,6 +6,7 @@ use Appwrite\Resque\Worker;
use Appwrite\Utopia\Response\Model\Deployment;
use Cron\CronExpression;
use Executor\Executor;
use Utopia\Database\Database;
use Utopia\Database\Validator\Authorization;
use Utopia\App;
use Utopia\CLI\Console;
@ -184,8 +185,8 @@ class BuildsV1 extends Worker
/** Update function schedule */
$schedule = $function->getAttribute('schedule', '');
$cron = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? new CronExpression($schedule) : null;
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : 0;
$function->setAttribute('scheduleNext', (int)$next);
$next = (empty($function->getAttribute('deployment')) && !empty($schedule)) ? Database::dateFormat($cron->getNextRunDate()) : null;
$function->setAttribute('scheduleNext', $next);
$function = $dbForProject->updateDocument('functions', $function->getId(), $function);
} catch (\Throwable $th) {
$endtime = \time();

View file

@ -147,22 +147,18 @@ class FunctionsV1 extends Worker
}
$cron = new CronExpression($function->getAttribute('schedule'));
$next = (int) $cron->getNextRunDate()->format('U');
$next = Database::dateFormat($cron->getNextRunDate());
$function
->setAttribute('scheduleNext', $next)
->setAttribute('schedulePrevious', \time());
->setAttribute('schedulePrevious', Database::getCurrentDateTime());
$function = $database->updateDocument(
'functions',
$function->getId(),
$function->setAttribute('scheduleNext', (int) $next)
$function->setAttribute('scheduleNext', $next)
);
if ($function === false) {
throw new Exception('Function update failed.');
}
$reschedule = new Func();
$reschedule
->setFunction($function)

View file

@ -81,16 +81,16 @@ class Func extends Model
'example' => '5 4 * * *',
])
->addRule('scheduleNext', [
'type' => self::TYPE_INTEGER,
'description' => 'Function next scheduled execution date in Unix timestamp.',
'default' => 0,
'example' => 1592981292,
'type' => self::TYPE_DATETIME,
'description' => 'Function next scheduled execution date in Datetime.',
'default' => '',
'example' => '1975-12-06 13:30:59',
])
->addRule('schedulePrevious', [
'type' => self::TYPE_INTEGER,
'description' => 'Function next scheduled execution date in Unix timestamp.',
'default' => 0,
'example' => 1592981237,
'type' => self::TYPE_DATETIME,
'description' => 'Function Previous scheduled execution date in Datetime.',
'default' => '',
'example' => '1975-12-06 13:30:59',
])
->addRule('timeout', [
'type' => self::TYPE_INTEGER,

View file

@ -916,7 +916,7 @@ class WebhooksCustomClientTest extends Scope
$this->assertNotEmpty($webhook['data']['userId']);
$this->assertNotEmpty($webhook['data']['teamId']);
$this->assertCount(2, $webhook['data']['roles']);
$this->assertIsInt($webhook['data']['joined']);
$this->assertIsString($webhook['data']['joined']);
$this->assertEquals(true, $webhook['data']['confirm']);
/**