Skip to content

Commit dd5d9d2

Browse files
committed
Merge branch 'ACP2E-82' of https://github.com/magento-l3/magento2ce into L3-PR-20211001
2 parents 8fd0bc5 + ab16bc3 commit dd5d9d2

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

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

Lines changed: 15 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,10 @@ 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+
if ($retries === 1) {
870+
throw new CronException(__('Could not acquire lock for cron job: %1', $schedule->getJobCode()));
871+
}
862872
}
863-
} catch (\Exception $e) {
864-
$this->processError($schedule, $e);
865873
} finally {
866874
$this->lockManager->unlock($lockName);
867875
}

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ public function testDispatchCanNotLock(): void
307307
$schedule->expects($this->atLeastOnce())->method('getScheduledAt')->willReturn($dateScheduledAt);
308308
$schedule->expects($this->exactly(5))->method('tryLockJob')->willReturn(false);
309309
$schedule->expects($this->never())->method('setFinishedAt');
310-
$schedule->expects($this->once())->method('getResource')->willReturn($this->scheduleResourceMock);
310+
$schedule->expects($this->never())->method('getResource')->willReturn($this->scheduleResourceMock);
311311

312312
$connectionMock = $this->getMockForAbstractClass(AdapterInterface::class);
313313

314-
$this->scheduleResourceMock->expects($this->once())
314+
$this->scheduleResourceMock->expects($this->never())
315315
->method('getConnection')
316316
->willReturn($connectionMock);
317317

318-
$this->retrierMock->expects($this->once())
318+
$this->retrierMock->expects($this->never())
319319
->method('execute')
320320
->willReturnCallback(
321321
function ($callback) {
@@ -341,7 +341,9 @@ function ($callback) {
341341
$this->scheduleFactoryMock->expects($this->atLeastOnce())
342342
->method('create')
343343
->willReturn($scheduleMock);
344-
344+
$this->loggerMock->expects($this->once())
345+
->method('warning')
346+
->with('Could not acquire lock for cron job: test_job1');
345347
$this->cronQueueObserver->execute($this->observerMock);
346348
}
347349

0 commit comments

Comments
 (0)