From eebb9d5d8f0843e709cbf67bd3e45cfee7e93b3e Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Fri, 1 Jul 2022 17:48:11 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20mq=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D0=B4?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=B5=D1=82=D1=87=D0=B5=D1=80=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=87=D0=B5=D1=80=D0=B5=D0=B4=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/cron.php | 9 ++++++++- core/lib/Core/Models/MQ.class.php | 33 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/cron.php b/core/cron.php index d45165e..1295597 100644 --- a/core/cron.php +++ b/core/cron.php @@ -1,5 +1,12 @@ run(); \ No newline at end of file + try { + (new MQ())->run(); + } catch (Throwable $t) { + echo 'Error: ' . $t->getMessage(); + } \ No newline at end of file diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index 5b485d2..66b9eb9 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -36,7 +36,7 @@ /** * Количество задач для обработки */ - const EXECUTION_TASKS_LIMIT = 2; + const EXECUTION_TASKS_LIMIT = 10; /** * @var DB|null $DB Объект базы @@ -65,6 +65,18 @@ return Log::logToFile('Тестирование сработало видимо.', 'MQ_test.log', func_get_args()); } + /** + * Тестовая функция 2 + * + * @return int + * @throws \Core\CoreException + */ + public static function test2(): int + { + sleep(5); + return Log::logToFile('Тестирование2', 'MQ_test.log', func_get_args()); + } + /** * Выборка активных невыполненных заданий из очереди * @@ -86,8 +98,9 @@ { return $this->DB->getItems( self::TABLE, [ - 'active' => self::VALUE_Y, - 'executed' => self::VALUE_N, + 'active' => self::VALUE_Y, + 'in_progres' => self::VALUE_N, + 'executed' => self::VALUE_N, ] ); } @@ -106,11 +119,8 @@ // Вычисляем сколько заданий требуется докинуть $num = self::EXECUTION_TASKS_LIMIT - $countTasks; $arTasks = $this->DB->query( - 'SELECT id FROM ' . self::TABLE - . ' WHERE active="' . self::VALUE_N - .'" AND executed="'. self::VALUE_N - . '" AND in_progress="' . self::VALUE_N - . '" LIMIT ' . $num + 'SELECT id FROM ' . self::TABLE . ' WHERE active="' . self::VALUE_N . '" AND executed="' . self::VALUE_N . '" AND in_progress="' + . self::VALUE_N . '" LIMIT ' . $num ); if (!empty($arTasks)) { $arTaskIds = []; @@ -135,7 +145,12 @@ if (!empty($arTasks)) { foreach ($arTasks as $task) { $this->execute($task['id']); - SystemFunctions::sendTelegram('Выполнено задание с ID ' . $task['id']); + SystemFunctions::sendTelegram( + 'Выполнено задание с ID ' . $task['id'] . PHP_EOL . $task['class'] . '::' . $task['method'] . '()' . PHP_EOL . print_r( + $task['params'], + true + ) + ); } } }