From f16113dbb3a6dc1b99d3a1566283b81042f2e401 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 17 Jan 2021 02:07:43 +0200 Subject: [PATCH] Some minor fixes --- app/controllers/api/functions.php | 8 +++++--- app/workers/functions.php | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 7a9996fbd9..f8f70796cd 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -293,6 +293,7 @@ App::put('/v1/functions/:functionId') throw new Exception('Function not found', 404); } + $original = $function->getAttribute('schedule', ''); $cron = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? CronExpression::factory($schedule) : null; $next = (!empty($function->getAttribute('tag', null)) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null; @@ -313,7 +314,7 @@ App::put('/v1/functions/:functionId') throw new Exception('Failed saving function to DB', 500); } - if ($next) { + if ($next && $schedule !== $original) { ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), 'functionId' => $function->getId(), @@ -358,8 +359,9 @@ App::patch('/v1/functions/:functionId/tag') } $schedule = $function->getAttribute('schedule', ''); - $cron = (empty($function->getAttribute('tag') && !empty($schedule))) ? CronExpression::factory($schedule) : null; - $next = (empty($function->getAttribute('tag') && !empty($schedule))) ? $cron->getNextRunDate()->format('U') : null; + var_dump($schedule); + $cron = (empty($function->getAttribute('tag')) && !empty($schedule)) ? CronExpression::factory($schedule) : null; + $next = (empty($function->getAttribute('tag')) && !empty($schedule)) ? $cron->getNextRunDate()->format('U') : null; $function = $projectDB->updateDocument(array_merge($function->getArrayCopy(), [ 'tag' => $tag->getId(), diff --git a/app/workers/functions.php b/app/workers/functions.php index 222b76a60d..6c3ba252b3 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -226,10 +226,14 @@ class FunctionsV1 ->setAttribute('schedulePrevious', \time()) ; + Authorization::disable(); + $function = $database->updateDocument(array_merge($function->getArrayCopy(), [ 'scheduleNext' => $next, ])); + Authorization::reset(); + ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $projectId, 'functionId' => $function->getId(),