[+] mq + executor

This commit is contained in:
rsgrinko committed 2022-07-01 15:39:46 +03:00
1 parent 751580d824
commit c2a3a925a2
3 files changed
+22 -10

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ if (User::isAuthorized()) {
header('Location: index.php'); header('Location: index.php');
} else { } else {
$arErrors = []; $arErrors = [];
if ($_REQUEST['send'] === 'Y') { if (!empty($_REQUEST['send']) && $_REQUEST['send'] === 'Y') {
if (empty($_REQUEST['login'])) { if (empty($_REQUEST['login'])) {
$arErrors[] = 'Логин не задан'; $arErrors[] = 'Логин не задан';
+3 -3
View File
@@ -18,9 +18,9 @@
); );
Sentry\configureScope(function (Sentry\State\Scope $sentryScope) { Sentry\configureScope(function (Sentry\State\Scope $sentryScope) {
$sentryScope->setExtra('user_id', $_SESSION['id']); $sentryScope->setExtra('user_id', $_SESSION['id'] ?: '');
$sentryScope->setExtra('user_login', $_SESSION['login']); $sentryScope->setExtra('user_login', $_SESSION['login'] ?: '');
$sentryScope->setExtra('user_token', $_SESSION['token']); $sentryScope->setExtra('user_token', $_SESSION['token'] ?: '');
}); });
/* /*
try { try {
+18 -6
View File
@@ -19,9 +19,9 @@
$this->DB = DB::getInstance(); $this->DB = DB::getInstance();
} }
public static function test($params): void public static function test($name, $age): int
{ {
Log::logToFile('Тестирование сработало видимо', 'MQ_test.log', $params); return Log::logToFile('Тестирование сработало видимо.', 'MQ_test.log', func_get_args());
} }
@@ -32,7 +32,7 @@
'active' => 'N', 'active' => 'N',
'in_progress' => 'N', 'in_progress' => 'N',
'attempts' => '0', 'attempts' => '0',
'class' => str_replace('\\', '\\\\\\\\', $class), 'class' => str_replace('\\', '\\\\', $class),
'method' => $method, 'method' => $method,
'params' => json_encode($params, JSON_UNESCAPED_UNICODE), 'params' => json_encode($params, JSON_UNESCAPED_UNICODE),
] ]
@@ -42,6 +42,8 @@
public function execute(int $taskId) public function execute(int $taskId)
{ {
$arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]); $arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]);
$arTask['class'] = str_replace('\\\\', '\\', $arTask['class']);
$arTask['params'] = json_decode($arTask['params'], true);
$this->DB->update( $this->DB->update(
self::TABLE, ['id' => $taskId], [ self::TABLE, ['id' => $taskId], [
'active' => 'Y', 'active' => 'Y',
@@ -49,10 +51,19 @@
'attempts' => ((int)$arTask['attempts'] + 1), 'attempts' => ((int)$arTask['attempts'] + 1),
] ]
); );
//echo '<pre>'.print_r($arTask, true).'</pre>';die();
try { try {
$arTask['class']::$arTask['method']();
$this->DB->remove(self::TABLE, ['id' => $taskId]); $result = call_user_func_array($arTask['class'] . '::' . $arTask['method'], $arTask['params']);
//$this->DB->remove(self::TABLE, ['id' => $taskId]);
$this->DB->update(
self::TABLE, ['id' => $taskId], [
'active' => 'N',
'in_progress' => 'N',
'executed' => 'Y',
'response' => json_encode($result, JSON_UNESCAPED_UNICODE),
]
);
} catch (\Throwable $t) { } catch (\Throwable $t) {
$this->DB->update( $this->DB->update(
self::TABLE, ['id' => $taskId], [ self::TABLE, ['id' => $taskId], [
@@ -61,6 +72,7 @@
'response' => $t->getMessage(), 'response' => $t->getMessage(),
] ]
); );
echo $t->getMessage();
} }
} }
} }