[*] MQ фиксы багов с сохранением в историю несуществующей таски

This commit is contained in:
rsgrinko committed 2022-07-06 20:23:57 +03:00
1 parent 5d1c8c1073
commit 12d3acf09b
4 files changed
+59 -23

No files matched your search

+5
View File
@@ -39,6 +39,11 @@
*/
const ERROR_FILE_COPY = 501;
/**
* Ошибка SQL запроса
*/
const ERROR_SQL_QUERY = 600;
/**
* Возвращает обработанный callTrace текущего исключения
*
+7 -1
View File
@@ -3,6 +3,8 @@
namespace Core\Models;
use Core\CoreException;
/**
* Класс для работы с базой данных
*
@@ -178,7 +180,11 @@
{
$startTime = microtime(true);
self::$quantity++;
$stmt = $this->db->query($sql);
try {
$stmt = $this->db->query($sql);
} catch (\Throwable $t) {
throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY);
}
$this->lastInsertId = $this->db->lastInsertId() ?? null;
$endTime = microtime(true);
self::$workingTime += ($endTime - $startTime);
+23 -17
View File
@@ -502,7 +502,8 @@
false
);
echo $t->getMessage() . ' on line ' . $t->getLine() . PHP_EOL;
// TODO: Следующая строка нужна больше для отладки - в дальнейшем нужно удалить ее
echo 'Exception: ' . $t->getFile() . ' в строке ' . $t->getLine() . PHP_EOL . $t->getMessage() . PHP_EOL;
}
return $response;
@@ -519,22 +520,27 @@
private function saveExecutedTask(int $taskId): ?int
{
$arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]);
$taskHistoryId = $this->DB->addItem(
self::TABLE_HISTORY, [
'task_id' => $arTask['id'],
'execution_time' => $arTask['execution_time'],
'attempts' => $arTask['attempts'],
'date_created' => $arTask['date_created'],
'date_updated' => $arTask['date_updated'],
'class' => addslashes($arTask['class']),
'method' => $arTask['method'],
'params' => $arTask['params'],
'status' => $arTask['status'],
'response' => $arTask['response'],
]
);
$this->removeTask($taskId);
return $taskHistoryId;
if(!empty($arTask)) {
$taskHistoryId = $this->DB->addItem(
self::TABLE_HISTORY, [
'task_id' => $arTask['id'],
'execution_time' => $arTask['execution_time'],
'attempts' => $arTask['attempts'],
'date_created' => $arTask['date_created'],
'date_updated' => $arTask['date_updated'],
'class' => addslashes($arTask['class']),
'method' => $arTask['method'],
'params' => $arTask['params'],
'status' => $arTask['status'],
'response' => $arTask['response'],
]
);
$this->removeTask($taskId);
return $taskHistoryId;
}
return null;
}
+24 -5
View File
@@ -37,7 +37,7 @@
private $paramsJson = null;
/**
* @var $response Результат выполнения задания
* @var string|null $response Результат выполнения задания
*/
private $response = null;
@@ -81,13 +81,32 @@
return $this->status;
}
/**
* Получение параметров
*
* @return array|null
*/
public function getParams(): ?array
{
return $this->params;
}
/**
* Получение JSON параметров
*
* @return string|null
*/
public function getParamsJson(): ?string
{
return $this->paramsJson;
}
/**
* Установка текстового кода ответа внешней службы
*
* @param string $status Текстовый код ответа
*
* @return $this
* @throws CoreException
*/
public function setStatus(string $status): self
{
@@ -112,7 +131,7 @@
*
* @param string|null $response Результат работы задания
*
* @return Response
* @return $this
*/
public function setResponse(?string $response = null): self
{
@@ -122,7 +141,7 @@
/**
* Установка массива парамтров задания
* Установка массива параметров задания
*
* @param array|null $params
*
@@ -135,7 +154,7 @@
}
/**
* Установка массива парамтров задания
* Установка массива параметров задания
*
* @param array $params
*