1
0
Fork 0
mirror of synced 2024-10-04 20:23:51 +13:00

Fix scheduler bugs

This commit is contained in:
Matej Bačo 2023-03-14 15:10:36 +01:00
parent c01fcb130c
commit a919421b47
3 changed files with 436 additions and 692 deletions

View file

@ -423,19 +423,10 @@ App::put('/v1/functions/:functionId')
]))); ])));
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
/**
* In case we want to clear the schedule
*/
if (!empty($function->getAttribute('deployment'))) {
$schedule->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'));
}
$schedule $schedule
->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'))
->setAttribute('schedule', $function->getAttribute('schedule')) ->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment'))); ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$eventsInstance->setParam('functionId', $function->getId()); $eventsInstance->setParam('functionId', $function->getId());
@ -488,19 +479,15 @@ App::patch('/v1/functions/:functionId/deployments/:deploymentId')
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [ $function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'deploymentInternalId' => $deployment->getInternalId(), 'deploymentInternalId' => $deployment->getInternalId(),
'deployment' => $deployment->getId() 'deployment' => $deployment->getId(),
'scheduleUpdatedAt' => DateTime::now()
]))); ])));
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule
$active = !empty($function->getAttribute('schedule')); ->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'))
->setAttribute('schedule', $function->getAttribute('schedule'))
if ($active) { ->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
$schedule->setAttribute('resourceUpdatedAt', datetime::now());
}
$schedule->setAttribute('active', $active);
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$events $events
@ -543,12 +530,9 @@ App::delete('/v1/functions/:functionId')
} }
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId')); $schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule $schedule
->setAttribute('resourceUpdatedAt', DateTime::now()) ->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('active', false) ->setAttribute('active', false);
;
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule)); Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$deletes $deletes
@ -749,22 +733,6 @@ App::post('/v1/functions/:functionId/deployments')
} }
} }
/**
* TODO Should we update also the function collection with the scheduleUpdatedAt attr?
*/
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$active = !empty($function->getAttribute('schedule'));
if ($active) {
$schedule->setAttribute('resourceUpdatedAt', datetime::now());
}
$schedule->setAttribute('active', $active);
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$metadata = null; $metadata = null;
$events $events
@ -1347,7 +1315,8 @@ App::post('/v1/functions/:functionId/variables')
->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', false) ->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', false)
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->action(function (string $functionId, string $key, string $value, Response $response, Database $dbForProject) { ->inject('dbForConsole')
->action(function (string $functionId, string $key, string $value, Response $response, Database $dbForProject, Database $dbForConsole) {
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) { if ($function->isEmpty()) {
@ -1378,6 +1347,17 @@ App::post('/v1/functions/:functionId/variables')
$dbForProject->deleteCachedDocument('functions', $function->getId()); $dbForProject->deleteCachedDocument('functions', $function->getId());
$function = $dbForProject->getDocument('functions', $functionId);
$function->setAttribute('scheduleUpdatedAt', DateTime::now());
$dbForProject->updateDocument('functions', $function->getId(), $function);
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule
->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'))
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$response $response
->setStatusCode(Response::STATUS_CODE_CREATED) ->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic($variable, Response::MODEL_VARIABLE); ->dynamic($variable, Response::MODEL_VARIABLE);
@ -1463,7 +1443,8 @@ App::put('/v1/functions/:functionId/variables/:variableId')
->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', true) ->param('value', null, new Text(8192), 'Variable value. Max length: 8192 chars.', true)
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->action(function (string $functionId, string $variableId, string $key, ?string $value, Response $response, Database $dbForProject) { ->inject('dbForConsole')
->action(function (string $functionId, string $variableId, string $key, ?string $value, Response $response, Database $dbForProject, Database $dbForConsole) {
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
@ -1494,6 +1475,17 @@ App::put('/v1/functions/:functionId/variables/:variableId')
$dbForProject->deleteCachedDocument('functions', $function->getId()); $dbForProject->deleteCachedDocument('functions', $function->getId());
$function = $dbForProject->getDocument('functions', $functionId);
$function->setAttribute('scheduleUpdatedAt', DateTime::now());
$dbForProject->updateDocument('functions', $function->getId(), $function);
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule
->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'))
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$response->dynamic($variable, Response::MODEL_VARIABLE); $response->dynamic($variable, Response::MODEL_VARIABLE);
}); });
@ -1513,7 +1505,8 @@ App::delete('/v1/functions/:functionId/variables/:variableId')
->param('variableId', '', new UID(), 'Variable unique ID.', false) ->param('variableId', '', new UID(), 'Variable unique ID.', false)
->inject('response') ->inject('response')
->inject('dbForProject') ->inject('dbForProject')
->action(function (string $functionId, string $variableId, Response $response, Database $dbForProject) { ->inject('dbForConsole')
->action(function (string $functionId, string $variableId, Response $response, Database $dbForProject, Database $dbForConsole) {
$function = $dbForProject->getDocument('functions', $functionId); $function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) { if ($function->isEmpty()) {
@ -1532,5 +1525,16 @@ App::delete('/v1/functions/:functionId/variables/:variableId')
$dbForProject->deleteDocument('variables', $variable->getId()); $dbForProject->deleteDocument('variables', $variable->getId());
$dbForProject->deleteCachedDocument('functions', $function->getId()); $dbForProject->deleteCachedDocument('functions', $function->getId());
$function = $dbForProject->getDocument('functions', $functionId);
$function->setAttribute('scheduleUpdatedAt', DateTime::now());
$dbForProject->updateDocument('functions', $function->getId(), $function);
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule
->setAttribute('resourceUpdatedAt', $function->getAttribute('scheduleUpdatedAt'))
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$response->noContent(); $response->noContent();
}); });

View file

@ -81,15 +81,17 @@ Server::setResource('execute', function () {
$execution = $dbForProject->createDocument('executions', new Document([ $execution = $dbForProject->createDocument('executions', new Document([
'$id' => $executionId, '$id' => $executionId,
'$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))],
'functionId' => $functionId, 'functionId' => $function->getId(),
'deploymentId' => $deploymentId, 'deploymentId' => $deployment->getId(),
'functionInternalId' => $function->getInternalId(),
'deploymentInternalId' => $deployment->getInternalId(),
'trigger' => $trigger, 'trigger' => $trigger,
'status' => 'waiting', 'status' => 'waiting',
'statusCode' => 0, 'statusCode' => 0,
'response' => '', 'response' => '',
'stderr' => '', 'stderr' => '',
'duration' => 0.0, 'duration' => 0.0,
'search' => implode(' ', [$functionId, $executionId]), 'search' => implode(' ', [$function->getId(), $executionId]),
])); ]));
// TODO: @Meldiron Trigger executions.create event here // TODO: @Meldiron Trigger executions.create event here

1030
composer.lock generated

File diff suppressed because it is too large Load diff