From 5ff55bf7c789af06caa2e2af160ed33cfc1bf919 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 6 Jul 2022 14:03:00 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20MQ=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=82=D0=B0=D1=81=D0=BA=D0=B8=20(=D0=B5=D1=81=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D1=83?= =?UTF-8?q?=D0=B5=D1=82=20-=20=D0=BD=D0=B5=20=D0=BF=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Core/Models/MQ.class.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index 3106ebc..83f82f8 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -108,7 +108,7 @@ */ private function convertFromJson(?string $json): array { - if(empty($json)) { + if (empty($json)) { return []; } return json_decode($json, true); @@ -257,6 +257,20 @@ ); } + /** + * Удаления задания из очереди + * + * @param int|null $taskId Идентификатор задания + * + * @throws CoreException + */ + public function removeTask(?int $taskId = null): bool + { + if (empty($id)) { + throw new CoreException('Не передан идентификатор задания'); + } + return $this->DB->remove(self::TABLE, ['id' => $taskId]); + } /** * Проверка задания на дубликат @@ -282,13 +296,14 @@ * @param int $taskId Идентификатор задания * * @return bool Флаг результата выполнения задания + * @throws CoreException */ public function execute(int $taskId): bool { $executeStatus = true; $arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]); - if ($arTask['in_progress'] === self::VALUE_Y) { - // Данное задание уже выполняется другим воркером + if (empty($arTask) || $arTask['in_progress'] === self::VALUE_Y) { + // Данное задание уже выполнено или выполняется другим воркером return false; } @@ -389,11 +404,11 @@ * @param int $taskId Идентификатор задачи * * @return int|null Идентификатор задачи в истории + * @throws CoreException */ private function saveExecutedTask(int $taskId): ?int { - $arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]); - + $arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]); $taskHistoryId = $this->DB->addItem( self::TABLE_HISTORY, [ 'task_id' => $arTask['id'], @@ -408,8 +423,7 @@ 'response' => $arTask['response'], ] ); - $this->DB->remove(self::TABLE, ['id' => $taskId]); - + $this->removeTask($taskId); return $taskHistoryId; }