diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..035682f --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (c) 2022 Roman Grinko + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/admin/threads.php b/admin/threads.php index b4e1b18..bfb5a6b 100644 --- a/admin/threads.php +++ b/admin/threads.php @@ -34,6 +34,7 @@ Всего + Воркеров Активных Выполняются С ошибкой @@ -43,6 +44,7 @@ getCountTasks();?> + getCountWorkers() . ' / ' . MQ::WORKERS_LIMIT;?> getCountTasks(['active' => 'Y']);?> getCountTasks(['active' => 'Y', 'in_progress' => 'Y']);?> getCountTasks(['in_progress' => 'N', 'status' => MQ::STATUS_ERROR]);?> diff --git a/core/lib/Core/MQTasks.class.php b/core/lib/Core/MQTasks.class.php index 90fbc82..476f237 100644 --- a/core/lib/Core/MQTasks.class.php +++ b/core/lib/Core/MQTasks.class.php @@ -132,12 +132,8 @@ $text = htmlspecialchars_decode($text); $text = str_replace('\'', '\\\'', $text); $hash = md5($text); - $res = $DB->query('SELECT * FROM bashorg WHERE hash="' . $hash . '"'); - if (!$res) { - $i++; - $itemId = $DB->addItem('bashorg', ['hash' => $hash, 'text' => $text, 'etx_id' => (int)$element['id'], 'date' => $element['date'], 'rating' => $element['rating']]); - sendTelegram('Добавлена цитата ID ' . $itemId . ' (' . $page . ' страница)' . PHP_EOL . $text); - } else { + $res = $DB->query('SELECT * FROM bashorg WHERE hash="' . $hash . '" AND date is null'); + if ($res) { $j++; $DB->update('bashorg', ['hash' => $hash], ['ext_id' => (int)$element['id'], 'date' => $element['date'], 'rating' => $element['rating']]); } diff --git a/core/lib/Core/Models/DB.class.php b/core/lib/Core/Models/DB.class.php index 48050db..e83fa61 100644 --- a/core/lib/Core/Models/DB.class.php +++ b/core/lib/Core/Models/DB.class.php @@ -93,6 +93,8 @@ { if (!is_array($where)) { return $where; + }elseif (empty($where)){ + return '1'; } $where_string = ''; foreach ($where as $where_key => $where_item) { diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index 893ba17..13e9113 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -59,9 +59,9 @@ const EXECUTION_TASKS_LIMIT = 100; /** - * Лимит количества одновременно выполняемых задач + * Лимит количества запущенных воркеров */ - const WORKERS_LIMIT = 5; + const WORKERS_LIMIT = 10; /** * @var DB|null $DB Объект базы @@ -81,7 +81,7 @@ /** * Время, после которого задача считается повисшей (5 минут) */ - const STUCK_TIME = 60 * 5; + const STUCK_TIME = 60 * 10; /** * @var null $priority Приоритет задания @@ -717,6 +717,17 @@ return (int)exec('ps -awx | grep \'threadsWorker.php\' | grep -v \'grep\' | wc -l'); } + /** + * Принудительная остановка всех запущенных воркеров + * + * @return void + */ + public function stopAllWorkers(): void + { + exec('pkill -f threadsWorker.php'); + $this->DB->update(self::TABLE, [], ['active' => 'N', 'in_progress' => 'N']); + } + /** * Проверка на максимальное количество работающих воркеров