Skip to content

Commit f17eda1

Browse files
committed
ACP2E-82: Same cron job executes twice
1 parent ac88ad9 commit f17eda1

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\App\State;
1515
use Magento\Framework\Console\Cli;
1616
use Magento\Framework\Event\ObserverInterface;
17+
use Magento\Framework\Exception\CronException;
1718
use Magento\Framework\Profiler\Driver\Standard\Stat;
1819
use Magento\Framework\Profiler\Driver\Standard\StatFactory;
1920
use Magento\Cron\Model\DeadlockRetrierInterface;
@@ -822,10 +823,16 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre
822823
continue;
823824
}
824825

825-
$this->tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
826-
827-
if ($schedule->getStatus() === Schedule::STATUS_SUCCESS) {
828-
$processedJobs[$schedule->getJobCode()] = true;
826+
try {
827+
$this->tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
828+
if ($schedule->getStatus() === Schedule::STATUS_SUCCESS) {
829+
$processedJobs[$schedule->getJobCode()] = true;
830+
}
831+
} catch (CronException $e) {
832+
$this->logger->warning($e->getMessage());
833+
continue;
834+
} catch (\Exception $e) {
835+
$this->processError($schedule, $e);
829836
}
830837

831838
$this->retrier->execute(
@@ -845,6 +852,7 @@ function () use ($schedule) {
845852
* @param string[] $jobConfig
846853
* @param Schedule $schedule
847854
* @param string $groupId
855+
* @throws CronException
848856
*/
849857
private function tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
850858
{
@@ -858,10 +866,8 @@ private function tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule,
858866
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
859867
break;
860868
}
861-
$this->logger->warning("Could not acquire lock for cron job: {$schedule->getJobCode()}");
869+
throw new CronException(__('Could not acquire lock for cron job: %1', $schedule->getJobCode()));
862870
}
863-
} catch (\Exception $e) {
864-
$this->processError($schedule, $e);
865871
} finally {
866872
$this->lockManager->unlock($lockName);
867873
}

0 commit comments

Comments
 (0)