From 6843ff49dc489a58ebef9c2af36c1b229d7a08ce Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Tue, 10 Dec 2024 16:16:07 +0100 Subject: [PATCH] Fix timezone for setting job next run --- lib/Action/SynchronizationAction.php | 5 +++-- lib/Cron/ActionTask.php | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/Action/SynchronizationAction.php b/lib/Action/SynchronizationAction.php index 12cc978..1bd27db 100644 --- a/lib/Action/SynchronizationAction.php +++ b/lib/Action/SynchronizationAction.php @@ -72,11 +72,12 @@ public function run(array $argument = []): array try { $objects = $this->synchronizationService->synchronize($synchronization); } catch (TooManyRequestsHttpException $e) { + $response['level'] = 'WARNING'; + $response['stackTrace'][] = $response['message'] = 'Stopped synchronization: ' . $e->getMessage(); if (isset($e->getHeaders()['X-RateLimit-Reset']) === true) { $response['nextRun'] = $e->getHeaders()['X-RateLimit-Reset']; + $response['stackTrace'][] = $response['message'] = 'Returning X-RateLimit-Reset header to update Job nextRun: ' . $response['nextRun']; } - $response['level'] = 'WARNING'; - $response['stackTrace'][] = $response['message'] = 'Stopped synchronization: ' . $e->getMessage(); return $response; } catch (Exception $e) { $response['level'] = 'ERROR'; diff --git a/lib/Cron/ActionTask.php b/lib/Cron/ActionTask.php index 45e12e6..8c51506 100644 --- a/lib/Cron/ActionTask.php +++ b/lib/Cron/ActionTask.php @@ -86,10 +86,22 @@ public function run($argument) // if the next run is in the the future, we don't need to do anything if ($job->getNextRun() !== null && $job->getNextRun() > new DateTime()) { - return; + $jobLog = $this->jobLogMapper->createFromArray([ + 'level' => 'WARNING', + 'message' => 'Next Run is still in the future for this job', + 'jobId' => $job->getId(), + 'jobClass' => $job->getJobClass(), + 'jobListId' => $job->getJobListId(), + 'arguments' => $job->getArguments(), + 'lastRun' => $job->getLastRun(), + 'nextRun' => $job->getNextRun(), + 'executionTime' => 0 + ]); + + return $jobLog; } - if(empty($job->getUserId()) === false && $this->userSession->getUser() === null) { + if (empty($job->getUserId()) === false && $this->userSession->getUser() === null) { $user = $this->userManager->get($job->getUserId()); $this->userSession->setUser($user); } @@ -111,11 +123,10 @@ public function run($argument) $job->setIsEnabled(false); } - // Update the job $nextRun = new DateTime('now + '.$job->getInterval().' seconds'); if (isset($result['nextRun']) === true) { - $nextRun = DateTime::createFromFormat('U', $result['nextRun']); + $nextRun = DateTime::createFromFormat('U', $result['nextRun'], $nextRun->getTimezone()); // Check if the current seconds part is not zero, and if so, round up to the next minute if ($nextRun->format('s') !== '00') { $nextRun->modify('next minute');