Skip to content

Commit 9038be8

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

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,9 @@ private function tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule,
866866
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
867867
break;
868868
}
869-
throw new CronException(__('Could not acquire lock for cron job: %1', $schedule->getJobCode()));
869+
if ($retries === 1) {
870+
throw new CronException(__('Could not acquire lock for cron job: %1', $schedule->getJobCode()));
871+
}
870872
}
871873
} finally {
872874
$this->lockManager->unlock($lockName);

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)