|
| 1 | +diff --git a/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php b/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php |
| 2 | +index a4a11156956d..d58e60ba2cab 100644 |
| 3 | +--- a/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php |
| 4 | ++++ b/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php |
| 5 | +@@ -320,17 +320,11 @@ private function lockGroup(string $groupId, callable $callback): void |
| 6 | + * |
| 7 | + * @return void |
| 8 | + * @throws Exception|Throwable |
| 9 | ++ * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 10 | + */ |
| 11 | + protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId) |
| 12 | + { |
| 13 | + $jobCode = $schedule->getJobCode(); |
| 14 | +- $scheduleLifetime = $this->getCronGroupConfigurationValue($groupId, self::XML_PATH_SCHEDULE_LIFETIME); |
| 15 | +- $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE; |
| 16 | +- if ($scheduledTime < $currentTime - $scheduleLifetime) { |
| 17 | +- $schedule->setStatus(Schedule::STATUS_MISSED); |
| 18 | +- // phpcs:ignore Magento2.Exceptions.DirectThrow |
| 19 | +- throw new Exception(sprintf('Cron Job %s is missed at %s', $jobCode, $schedule->getScheduledAt())); |
| 20 | +- } |
| 21 | + |
| 22 | + if (!isset($jobConfig['instance'], $jobConfig['method'])) { |
| 23 | + $schedule->setStatus(Schedule::STATUS_ERROR); |
| 24 | +@@ -832,7 +826,7 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre |
| 25 | + } |
| 26 | + |
| 27 | + $scheduledTime = strtotime($schedule->getScheduledAt()); |
| 28 | +- if ($scheduledTime > $currentTime) { |
| 29 | ++ if (!$this->shouldRunJob($schedule, $groupId, $currentTime, (int) $scheduledTime)) { |
| 30 | + continue; |
| 31 | + } |
| 32 | + |
| 33 | +@@ -929,4 +923,62 @@ function () use ($scheduleResource, $where) { |
| 34 | + $scheduleResource->getConnection() |
| 35 | + ); |
| 36 | + } |
| 37 | ++ |
| 38 | ++ /** |
| 39 | ++ * Mark job as missed |
| 40 | ++ * |
| 41 | ++ * @param Schedule $schedule |
| 42 | ++ * @return void |
| 43 | ++ */ |
| 44 | ++ private function markJobAsMissed(Schedule $schedule): void |
| 45 | ++ { |
| 46 | ++ $jobCode = $schedule->getJobCode(); |
| 47 | ++ $scheduleId = $schedule->getId(); |
| 48 | ++ $resource = $schedule->getResource(); |
| 49 | ++ $connection = $resource->getConnection(); |
| 50 | ++ $message = sprintf('Cron Job %s is missed at %s', $jobCode, $schedule->getScheduledAt()); |
| 51 | ++ $result = $this->retrier->execute( |
| 52 | ++ function () use ($resource, $connection, $scheduleId, $message) { |
| 53 | ++ return $connection->update( |
| 54 | ++ $resource->getTable('cron_schedule'), |
| 55 | ++ ['status' => Schedule::STATUS_MISSED, 'messages' => $message], |
| 56 | ++ ['schedule_id = ?' => $scheduleId, 'status = ?' => Schedule::STATUS_PENDING] |
| 57 | ++ ); |
| 58 | ++ }, |
| 59 | ++ $connection |
| 60 | ++ ); |
| 61 | ++ if ($result == 1) { |
| 62 | ++ $schedule->setStatus(Schedule::STATUS_MISSED); |
| 63 | ++ $schedule->setMessages($message); |
| 64 | ++ if ($this->state->getMode() === State::MODE_DEVELOPER) { |
| 65 | ++ $this->logger->info($message); |
| 66 | ++ } |
| 67 | ++ } |
| 68 | ++ } |
| 69 | ++ |
| 70 | ++ /** |
| 71 | ++ * Check if job should be run |
| 72 | ++ * |
| 73 | ++ * @param Schedule $schedule |
| 74 | ++ * @param string $groupId |
| 75 | ++ * @param int $currentTime |
| 76 | ++ * @param int $scheduledTime |
| 77 | ++ * @return bool |
| 78 | ++ */ |
| 79 | ++ private function shouldRunJob(Schedule $schedule, string $groupId, int $currentTime, int $scheduledTime): bool |
| 80 | ++ { |
| 81 | ++ if ($scheduledTime > $currentTime) { |
| 82 | ++ return false; |
| 83 | ++ } |
| 84 | ++ |
| 85 | ++ $scheduleLifetime = $this->getCronGroupConfigurationValue($groupId, self::XML_PATH_SCHEDULE_LIFETIME); |
| 86 | ++ $scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE; |
| 87 | ++ |
| 88 | ++ if ($scheduledTime < $currentTime - $scheduleLifetime) { |
| 89 | ++ $this->markJobAsMissed($schedule); |
| 90 | ++ return false; |
| 91 | ++ } |
| 92 | ++ |
| 93 | ++ return true; |
| 94 | ++ } |
| 95 | + } |
0 commit comments