доработка диспетчера очереди

This commit is contained in:
rsgrinko committed 2022-11-16 15:00:00 +03:00
1 parent 8be867d0ce
commit 64c4e62ca3
7 files changed
+79 -7

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@
</thead> </thead>
<tbody> <tbody>
<?php <?php
$arTasks = $MQ->getTasks(10, 'priority', 'asc'); $arTasks = $MQ->getTasks(10, 'in_progress', 'desc');
foreach ($arTasks as $task) { foreach ($arTasks as $task) {
?> ?>
<tr class="<?php <tr class="<?php
+32 -1
View File
@@ -22,7 +22,7 @@
@ignore_user_abort(true); @ignore_user_abort(true);
set_time_limit(0); set_time_limit(0);
use Core\Helpers\Cache; use Core\Helpers\Log;
use Core\Models\MQ; use Core\Models\MQ;
if (empty($_SERVER['DOCUMENT_ROOT'])) { if (empty($_SERVER['DOCUMENT_ROOT'])) {
@@ -34,3 +34,34 @@
exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1'); exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1');
//$result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); //$result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO');
// Попытка получения валюты сайта за ежедневные авторизации
$cookieFile = $_SERVER['DOCUMENT_ROOT'] . '/uploads/visaviCookie.txt';
$logFileName = 'visavi.log';
if (!file_exists($cookieFile) || time() - @filectime($cookieFile) > 60 * 60 * 23) {
Log::logToFile('Время пришло - начинаем попытку авторизации', $logFileName);
@unlink($cookieFile);
Log::logToFile('Файл куков удален', $logFileName);
$array = [
'login' => 'Nominal',
'password' => 'j2medit',
];
$ch = curl_init('https://visavi.net/login');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array, '', '&'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$html = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
unset($html);
Log::logToFile('Запрос на авторизацию произведен. Код ответа: ' . $httpCode, $logFileName);
}
@@ -739,4 +739,18 @@
} }
return $result; return $result;
} }
/**
* Получение количества ядер процессора площадки
*
* @return int Количество ядер
*/
public static function getCPUCount(): int
{
$count = (int)shell_exec('cat /proc/cpuinfo | grep processor | wc -l');
if ($count === 0) {
$count = 1;
}
return $count;
}
} }
+20
View File
@@ -421,4 +421,24 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
return ['count' => $counter, 'files' => $files]; return ['count' => $counter, 'files' => $files];
} }
public static function saveVisaviThreads(int $page = 1)
{
//181
$link = 'https://visavi.net/api/forums/3?token=27e11369d8c770b3cb6d5e211a5aab99&page=' . $page;
$res = file_get_contents($link);
$res = json_decode($res, true, 512, JSON_THROW_ON_ERROR);
if (empty($res['data'])) {
throw new CoreException('Данных для обработки не найдено');
}
$result= [];
/** @var DB $DB */
$DB = DB::getInstance();
foreach($res['data'] as $thread) {
$result[] = $DB->addItem('visavi_themes', ['thread_id' => (int)$thread['id'], 'title' => addslashes($thread['title'])]);
}
return $result;
}
} }
+6 -2
View File
@@ -216,9 +216,13 @@
$result = ''; $result = '';
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
if ($param == 'key') { if ($param == 'key') {
$result = $result . $k . ', '; $result .= $k . ', ';
} elseif ($param == 'value') { } elseif ($param == 'value') {
$result = $result . '\'' . addslashes($v) . '\', '; if (is_numeric($v)) {
$result .= $v . ', ';
} else {
$result .= '\'' . addslashes($v) . '\', ';
}
} }
} }
return substr($result, 0, -2); return substr($result, 0, -2);
+5 -3
View File
@@ -69,7 +69,7 @@
/** Попыток выполнения по умолчанию */ /** Попыток выполнения по умолчанию */
public const DEFAULT_ATTEMPTS = 1; public const DEFAULT_ATTEMPTS = 1;
/** Время, после которого задача считается повисшей (5 минут) */ /** Время, после которого задача считается повисшей (15 минут) */
public const STUCK_TIME = 60 * 15; public const STUCK_TIME = 60 * 15;
/** @var null $priority Приоритет задания */ /** @var null $priority Приоритет задания */
@@ -574,6 +574,7 @@
null, null,
false false
); );
Log::logToSentry($this->getWorkerId() . ': Задания ' . $taskId . ' не найдено', 'DEBUG', ['taskId' => $taskId]);
} }
return $response; return $response;
@@ -694,6 +695,7 @@
null, null,
false false
); );
Log::logToSentry($this->getWorkerId() . ': Ошибка выполнения задания с ID ' . $taskId . ', попытка ' . $arTask['attempts'] . ' из ' . $arTask['attempts_limit'], 'DEBUG', ['response' => $t->getMessage()]);
} }
} }
@@ -854,8 +856,8 @@
); );
if (!empty($runTasks)) { if (!empty($runTasks)) {
foreach ($runTasks as $task) { foreach ($runTasks as $task) {
if ((!empty($task['date_updated']) && (time() - strtotime($task['date_updated'])) > self::STUCK_TIME) // Повисшие надолго if (empty($task['date_updated']) // Криво запущенные
|| empty($task['date_updated']) // Криво запущенные || (time() - strtotime($task['date_updated'])) > self::STUCK_TIME // Повисшие надолго
) { ) {
$arStuckTasks[] = (int)$task['id']; $arStuckTasks[] = (int)$task['id'];
if (USE_LOG) { if (USE_LOG) {
+1
View File
@@ -24,6 +24,7 @@
*/ */
@ignore_user_abort(true); @ignore_user_abort(true);
set_time_limit(0); set_time_limit(0);
ini_set('memory_limit', '512M');
require_once __DIR__ . '/init.php'; require_once __DIR__ . '/init.php';