Skip to content

Commit

Permalink
fix: run cron job if never runned
Browse files Browse the repository at this point in the history
  • Loading branch information
rugbymauri committed Aug 9, 2023
1 parent b16fd8b commit 46a782a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Manager/ExecutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ public function getLastExecutionDate(CronInterface $cronJob): ?\DateTime
/**
* Return date of next execution or null if there is no previous run (run needed).
*/
public function getNextExecutionDate(CronInterface $cronJob): \DateTime
public function getNextExecutionDate(CronInterface $cronJob): ?\DateTime
{
$lastExecutionDate = $this->getLastExecutionDate($cronJob);
if (! $lastExecutionDate) {
return (new CronExpression($cronJob->getExpression()))
->getNextRunDate();
return null;
}

return (new CronExpression($cronJob->getExpression()))
Expand Down Expand Up @@ -114,9 +113,9 @@ public function isRunNeeded(CronInterface $cronJob): bool
// Get next execution date
$nextExecutionDate = $this->getNextExecutionDate($cronJob);
if (!$nextExecutionDate) {
$this->logger->debug(sprintf('%s do not need to run. Next run at %s', $cronJob::class, $nextExecutionDate->format('Y-m-d H:i:s')));
$this->logger->debug(sprintf('%s has no previous run. Scheduling it now.', $cronJob::class));

return false;
return true;
}

// Check if parallel execution allowed
Expand Down

0 comments on commit 46a782a

Please sign in to comment.