From 5d1c8c107307d2a1b3d0171bbd08909a2cf5ff56 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 6 Jul 2022 20:08:43 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20MQ=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20=D0=B4=D0=B8=D1=81=D0=BF=D0=B5?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=80=D0=B0=20=D0=BE=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B8,=20=D0=B2=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8=20=D0=BA=D0=BE=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=BF=D0=BE=D0=BF=D1=8B?= =?UTF-8?q?=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/threads.php | 8 +++++--- core/lib/Core/Models/MQ.class.php | 16 ++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/admin/threads.php b/admin/threads.php index 34da07b..3886cb3 100644 --- a/admin/threads.php +++ b/admin/threads.php @@ -105,9 +105,10 @@ ID Активен Выполняется - Выполнен + Приоритет Время выполнения Попытки + Лимит попыток Класс Метод Параметры @@ -119,16 +120,17 @@ getTasks(); + $arTasks = $MQ->getTasks(10, 'priority', 'asc'); foreach($arTasks as $task) { ?> - + + diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index afe742f..8166fd8 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -18,6 +18,11 @@ */ const TABLE_HISTORY = 'threads_history'; + /** + * Формат даты и времени + */ + const DATETIME_FORMAT = 'Y-m-d H:i:s'; + /** * Имя файла логов */ @@ -132,10 +137,9 @@ */ public static function test2(...$params): string { - throw new CoreException('Выполнение заблокировано'); sleep(rand(10, 30)); $result = rand(0, 100); - if ((int)$result === 27) { + if (($result % 2) == 0) { throw new CoreException('Сервер обмена временно недоступен'); } return 'Пользователь с ID ' . $params['0'] . ' обновлен'; @@ -452,7 +456,7 @@ 'in_progress' => self::VALUE_N, 'execution_time' => $endTime, 'status' => self::STATUS_OK, - 'date_updated' => date('Y-m-d H:i:s'), + 'date_updated' => date(self::DATETIME_FORMAT), 'response' => $this->convertToJson($result), ] ); @@ -475,7 +479,7 @@ 'active' => self::VALUE_Y, // Не снимаем активность пока не израсходуем все попытки 'in_progress' => self::VALUE_N, 'execution_time' => $endTime, - 'date_updated' => date('Y-m-d H:i:s'), + 'date_updated' => date(self::DATETIME_FORMAT), 'status' => self::STATUS_ERROR, 'response' => $t->getMessage(), ] @@ -541,9 +545,9 @@ * * @return mixed|null */ - public function getTasks(string $limit = '10'): ?array + public function getTasks(string $limit = '10', string $orderBy = 'id', string $sort = 'DESC'): ?array { - return $this->DB->query('SELECT * FROM ' . self::TABLE . ' ORDER BY id DESC LIMIT ' . $limit) ?? []; + return $this->DB->query('SELECT * FROM ' . self::TABLE . ' ORDER BY ' . $orderBy . ' ' . $sort . ' LIMIT ' . $limit) ?? []; } /**