Skip to content

Commit

Permalink
Fix timezone for setting job next run
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Dec 10, 2024
1 parent 43f4ac7 commit 6843ff4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/Action/SynchronizationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
19 changes: 15 additions & 4 deletions lib/Cron/ActionTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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');
Expand Down

0 comments on commit 6843ff4

Please sign in to comment.