From 9c0ce5ed7a7464c2022093fe2308d4722a862bba Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Wed, 28 Sep 2022 17:28:54 +0200 Subject: [PATCH] Refactor DaemonRun::afterProcess for better readability [MAILPOET-4684] --- .../ActionScheduler/Actions/DaemonRun.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mailpoet/lib/Cron/ActionScheduler/Actions/DaemonRun.php b/mailpoet/lib/Cron/ActionScheduler/Actions/DaemonRun.php index 32b1c76831..7778458efd 100644 --- a/mailpoet/lib/Cron/ActionScheduler/Actions/DaemonRun.php +++ b/mailpoet/lib/Cron/ActionScheduler/Actions/DaemonRun.php @@ -85,17 +85,21 @@ class DaemonRun { * After Action Scheduler finishes its work we need to check if there is more work and in case there is we trigger additional runner. */ public function afterProcess(): void { - $lastDurationWasTooShort = ($this->lastRunDuration < self::SHORT_DURATION_THRESHOLD) && ($this->remainingExecutionLimit > 0); - // Schedule next action in case we have more jobs to do. + $hasJobsToDo = $this->wordpressTrigger->checkExecutionRequirements(); + if (!$hasJobsToDo) { + return; + } // The $lastDurationWasTooShort check prevents scheduling the next immediate action in case the last run was suspiciously short. // If there was still some execution time left, the daemon should have been continued. - if ($this->wordpressTrigger->checkExecutionRequirements() && !$lastDurationWasTooShort) { - $this->actionScheduler->scheduleImmediateSingleAction(self::NAME); - // The automatic rescheduling schedules the next recurring action to run after 1 second. - // So we need to wait before we trigger new remote executor to avoid skipping the action - sleep(2); - $this->remoteExecutorHandler->triggerExecutor(); + $lastDurationWasTooShort = ($this->lastRunDuration < self::SHORT_DURATION_THRESHOLD) && ($this->remainingExecutionLimit > 0); + if ($lastDurationWasTooShort) { + return; } + $this->actionScheduler->scheduleImmediateSingleAction(self::NAME); + // The automatic rescheduling schedules the next recurring action to run after 1 second. + // So we need to wait before we trigger new remote executor to avoid skipping the action + sleep(2); + $this->remoteExecutorHandler->triggerExecutor(); } /**