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