scheduleNext + schedulePrevious functions changes
This commit is contained in:
parent
05f8352837
commit
e0f2d59864
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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']);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue