From 55b4051e3f46ad3b9e0542b71fc3b011ba6d9dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Wed, 19 May 2021 10:46:51 +0200 Subject: [PATCH] Add reset in progress state for sending queue tasks [MAILPOET-3608] --- .../Workers/SendingQueue/SendingQueue.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/Cron/Workers/SendingQueue/SendingQueue.php b/lib/Cron/Workers/SendingQueue/SendingQueue.php index 55f4664bcb..d8a80bcf31 100644 --- a/lib/Cron/Workers/SendingQueue/SendingQueue.php +++ b/lib/Cron/Workers/SendingQueue/SendingQueue.php @@ -97,7 +97,14 @@ class SendingQueue { $task = $queue->task(); if (!$task instanceof ScheduledTask) continue; - if ($this->isInProgress($task)) continue; + + if ($this->isInProgress($task)) { + if ($this->isTimeout($task)) { + $this->stopProgress($task); + } else { + continue; + } + } $this->startProgress($task); @@ -430,8 +437,20 @@ class SendingQueue { $task->save(); } - public function getExecutionLimit(): int { - // Convert seconds to minutes - return (int)round($this->cronHelper->getDaemonExecutionLimit() * 2 / 60); + private function isTimeout(ScheduledTask $task): bool { + $currentTime = Carbon::createFromTimestamp($this->wp->currentTime('timestamp')); + $updated = strtotime((string)$task->updatedAt); + if ($updated !== false) { + $updatedAt = Carbon::createFromTimestamp($updated); + } + if (isset($updatedAt) && $updatedAt->diffInSeconds($currentTime, false) > $this->getExecutionLimit()) { + return true; + } + + return false; + } + + private function getExecutionLimit(): int { + return $this->cronHelper->getDaemonExecutionLimit() * 3; } }