From c5a80d4171874ac12f77a4bc7111cdf0dc1c04eb Mon Sep 17 00:00:00 2001 From: Olivier Briat <41218-Teenage@users.noreply.drupalcode.org> Date: Fri, 13 Dec 2024 10:33:53 +0000 Subject: [PATCH] Issue #3383149 by o'briat, scott_euser: Simple cron log should not log non scheduled jobs --- src/Entity/CronJob.php | 8 ++++++-- tests/src/Unit/Entity/CronJobTest.php | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Entity/CronJob.php b/src/Entity/CronJob.php index a8b0b46..fcb54f4 100644 --- a/src/Entity/CronJob.php +++ b/src/Entity/CronJob.php @@ -323,8 +323,12 @@ class CronJob extends ConfigEntityBase implements CronJobInterface { try { $plugin = $this->getPlugin(); - if (!$plugin || !$this->shouldRun($request_time, $force)) { - $this->logger->warning('Cron job @job should not be running.', ['@job' => $this->label()]); + if (!$plugin) { + $this->logger->warning('Cron job @job could not be run: missing plugin.', ['@job' => $this->label()]); + return FALSE; + } + if (!$this->shouldRun($request_time, $force)) { + // Do nothing: this job is not scheduled to be run at this time. return FALSE; } diff --git a/tests/src/Unit/Entity/CronJobTest.php b/tests/src/Unit/Entity/CronJobTest.php index 1d08ff3..8bbf647 100644 --- a/tests/src/Unit/Entity/CronJobTest.php +++ b/tests/src/Unit/Entity/CronJobTest.php @@ -128,7 +128,12 @@ class CronJobTest extends UnitTestCase { $this->assertEquals($expected, $last_run_time_is_set, 'Last run time is correct.'); $this->assertEquals($expected, $status, 'Cron run is executed.'); - $this->assertEquals(!$locked, $this->state->get('state.message_logged'), 'Message is logged'); + if (!$locked && !$should_run) { + $this->assertEquals($locked, $this->state->get('state.message_logged'), 'Message is logged'); + } + else { + $this->assertEquals(!$locked, $this->state->get('state.message_logged'), 'Message is logged'); + } } /** -- GitLab