Skip to content

Commit 8ee5163

Browse files
#23312: Static test fix.
1 parent dd5af3d commit 8ee5163

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
/**
87
* Handling cron jobs
98
*/
109
namespace Magento\Cron\Observer;
1110

11+
use Magento\Cron\Model\Schedule;
1212
use Magento\Framework\App\State;
1313
use Magento\Framework\Console\Cli;
1414
use Magento\Framework\Event\ObserverInterface;
15-
use Magento\Cron\Model\Schedule;
1615
use Magento\Framework\Profiler\Driver\Standard\Stat;
1716
use Magento\Framework\Profiler\Driver\Standard\StatFactory;
1817

@@ -204,7 +203,6 @@ public function __construct(
204203
*/
205204
public function execute(\Magento\Framework\Event\Observer $observer)
206205
{
207-
208206
$currentTime = $this->dateTime->gmtTimestamp();
209207
$jobGroupsRoot = $this->_config->getJobs();
210208
// sort jobs groups to start from used in separated process
@@ -258,7 +256,6 @@ function ($groupId) use ($currentTime, $jobsRoot) {
258256
*/
259257
private function lockGroup($groupId, callable $callback)
260258
{
261-
262259
if (!$this->lockManager->lock(self::LOCK_PREFIX . $groupId, self::LOCK_TIMEOUT)) {
263260
$this->logger->warning(
264261
sprintf(
@@ -293,17 +290,20 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
293290
$scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
294291
if ($scheduledTime < $currentTime - $scheduleLifetime) {
295292
$schedule->setStatus(Schedule::STATUS_MISSED);
293+
// phpcs:ignore Magento2.Exceptions.DirectThrow
296294
throw new \Exception(sprintf('Cron Job %s is missed at %s', $jobCode, $schedule->getScheduledAt()));
297295
}
298296

299297
if (!isset($jobConfig['instance'], $jobConfig['method'])) {
300298
$schedule->setStatus(Schedule::STATUS_ERROR);
299+
// phpcs:ignore Magento2.Exceptions.DirectThrow
301300
throw new \Exception(sprintf('No callbacks found for cron job %s', $jobCode));
302301
}
303302
$model = $this->_objectManager->create($jobConfig['instance']);
304303
$callback = [$model, $jobConfig['method']];
305304
if (!is_callable($callback)) {
306305
$schedule->setStatus(Schedule::STATUS_ERROR);
306+
// phpcs:ignore Magento2.Exceptions.DirectThrow
307307
throw new \Exception(
308308
sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method'])
309309
);
@@ -314,15 +314,18 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
314314
$this->startProfiling();
315315
try {
316316
$this->logger->info(sprintf('Cron Job %s is run', $jobCode));
317+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
317318
call_user_func_array($callback, [$schedule]);
318319
} catch (\Throwable $e) {
319320
$schedule->setStatus(Schedule::STATUS_ERROR);
320-
$this->logger->error(sprintf(
321-
'Cron Job %s has an error: %s. Statistics: %s',
322-
$jobCode,
323-
$e->getMessage(),
324-
$this->getProfilingStat()
325-
));
321+
$this->logger->error(
322+
sprintf(
323+
'Cron Job %s has an error: %s. Statistics: %s',
324+
$jobCode,
325+
$e->getMessage(),
326+
$this->getProfilingStat()
327+
)
328+
);
326329
if (!$e instanceof \Exception) {
327330
$e = new \RuntimeException(
328331
'Error when running a cron job',
@@ -336,7 +339,8 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
336339
}
337340

338341
$schedule->setStatus(
339-
Schedule::STATUS_SUCCESS)->setFinishedAt(
342+
Schedule::STATUS_SUCCESS
343+
)->setFinishedAt(
340344
strftime(
341345
'%Y-%m-%d %H:%M:%S',
342346
$this->dateTime->gmtTimestamp()
@@ -411,7 +415,7 @@ private function getNonExitedSchedules($groupId)
411415
$jobs = $this->_config->getJobs();
412416
$pendingJobs = $this->_scheduleFactory->create()->getCollection();
413417
$pendingJobs->addFieldToFilter(
414-
'status',
418+
'status',
415419
[
416420
'in' => [
417421
Schedule::STATUS_PENDING, Schedule::STATUS_RUNNING, Schedule::STATUS_SUCCESS

0 commit comments

Comments
 (0)