[*] MQ переработка диспетчера очереди, введение приоритезации и количества попыток
This commit is contained in:
1 parent
54dbbb4485
commit
5d1c8c1073
2 files changed
+15
-9
No files matched your search
+5
-3
@@ -105,9 +105,10 @@
|
||||
<th>ID</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>
|
||||
<tbody>
|
||||
<?php
|
||||
$arTasks = $MQ->getTasks();
|
||||
$arTasks = $MQ->getTasks(10, 'priority', 'asc');
|
||||
foreach($arTasks as $task) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?=$task['id'];?></td>
|
||||
<td><?=$task['active'] === 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['attempts'];?></td>
|
||||
<td><?=$task['attempts_limit'];?></td>
|
||||
<td><?=$task['class'];?></td>
|
||||
<td><?=$task['method'];?></td>
|
||||
<td><?=$task['params'];?></td>
|
||||
|
||||
@@ -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) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user