[*] MQ переработка диспетчера очереди, введение приоритезации и количества попыток

This commit is contained in:
rsgrinko committed 2022-07-06 20:08:43 +03:00
1 parent 54dbbb4485
commit 5d1c8c1073
2 files changed
+15 -9

No files matched your search

+5 -3
View File
@@ -105,9 +105,10 @@
<th>ID</th> <th>ID</th>
<th>Активен</th> <th>Активен</th>
<th>Выполняется</th> <th>Выполняется</th>
<th>Выполнен</th> <th>Приоритет</th>
<th>Время выполнения</th> <th>Время выполнения</th>
<th>Попытки</th> <th>Попытки</th>
<th>Лимит попыток</th>
<th>Класс</th> <th>Класс</th>
<th>Метод</th> <th>Метод</th>
<th>Параметры</th> <th>Параметры</th>
@@ -119,16 +120,17 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
$arTasks = $MQ->getTasks(); $arTasks = $MQ->getTasks(10, 'priority', 'asc');
foreach($arTasks as $task) { foreach($arTasks as $task) {
?> ?>
<tr> <tr>
<td><?=$task['id'];?></td> <td><?=$task['id'];?></td>
<td><?=$task['active'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td> <td><?=$task['active'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td>
<td><?=$task['in_progress'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td> <td><?=$task['in_progress'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td>
<td><?=$task['executed'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td> <td><?=$task['priority'] === MQ::VALUE_Y ? 'Да' : 'Нет';?></td>
<td><?=$task['execution_time'];?></td> <td><?=$task['execution_time'];?></td>
<td><?=$task['attempts'];?></td> <td><?=$task['attempts'];?></td>
<td><?=$task['attempts_limit'];?></td>
<td><?=$task['class'];?></td> <td><?=$task['class'];?></td>
<td><?=$task['method'];?></td> <td><?=$task['method'];?></td>
<td><?=$task['params'];?></td> <td><?=$task['params'];?></td>
+10 -6
View File
@@ -18,6 +18,11 @@
*/ */
const TABLE_HISTORY = 'threads_history'; const TABLE_HISTORY = 'threads_history';
/**
* Формат даты и времени
*/
const DATETIME_FORMAT = 'Y-m-d H:i:s';
/** /**
* Имя файла логов * Имя файла логов
*/ */
@@ -132,10 +137,9 @@
*/ */
public static function test2(...$params): string public static function test2(...$params): string
{ {
throw new CoreException('Выполнение заблокировано');
sleep(rand(10, 30)); sleep(rand(10, 30));
$result = rand(0, 100); $result = rand(0, 100);
if ((int)$result === 27) { if (($result % 2) == 0) {
throw new CoreException('Сервер обмена временно недоступен'); throw new CoreException('Сервер обмена временно недоступен');
} }
return 'Пользователь с ID ' . $params['0'] . ' обновлен'; return 'Пользователь с ID ' . $params['0'] . ' обновлен';
@@ -452,7 +456,7 @@
'in_progress' => self::VALUE_N, 'in_progress' => self::VALUE_N,
'execution_time' => $endTime, 'execution_time' => $endTime,
'status' => self::STATUS_OK, 'status' => self::STATUS_OK,
'date_updated' => date('Y-m-d H:i:s'), 'date_updated' => date(self::DATETIME_FORMAT),
'response' => $this->convertToJson($result), 'response' => $this->convertToJson($result),
] ]
); );
@@ -475,7 +479,7 @@
'active' => self::VALUE_Y, // Не снимаем активность пока не израсходуем все попытки 'active' => self::VALUE_Y, // Не снимаем активность пока не израсходуем все попытки
'in_progress' => self::VALUE_N, 'in_progress' => self::VALUE_N,
'execution_time' => $endTime, 'execution_time' => $endTime,
'date_updated' => date('Y-m-d H:i:s'), 'date_updated' => date(self::DATETIME_FORMAT),
'status' => self::STATUS_ERROR, 'status' => self::STATUS_ERROR,
'response' => $t->getMessage(), 'response' => $t->getMessage(),
] ]
@@ -541,9 +545,9 @@
* *
* @return mixed|null * @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) ?? [];
} }
/** /**