[*] переработана система работы с кроновыми заданиями. Теперь добавить задание проще простого и не нужно постоянно лазить в кронтаб

This commit is contained in:
rsgrinko committed 2023-10-29 21:25:29 +03:00
1 parent c54cb5f9e1
commit b4f506cc1f
5 files changed
+104 -38

No files matched your search

+11 -36
View File
@@ -23,45 +23,20 @@
set_time_limit(0);
use Core\Helpers\Log;
use Core\Models\MQ;
if (empty($_SERVER['DOCUMENT_ROOT'])) {
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/..';
}
require_once __DIR__ . '/bootstrap.php';
// Запускаем воркер диспетчера очереди
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');
// Попытка получения валюты сайта за ежедневные авторизации
$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);
}
$tasksDir = __DIR__ . '/cronTasks/';
$list = scandir($tasksDir);
$logFileName = 'cron.log';
foreach ($list as $file) {
if (in_array($file, ['.', '..', 'init.php'], true)) {
continue;
}
$command = '(php -f ' . $tasksDir . $file . ' & ) >> /dev/null 2>&1';
Log::logToFile($command, $logFileName);
exec($command);
}
+29
View File
@@ -0,0 +1,29 @@
<?php
/**
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
* 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.
*/
@ignore_user_abort(true);
set_time_limit(0);
if (empty($_SERVER['DOCUMENT_ROOT'])) {
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/../..';
}
require_once __DIR__ . '/../bootstrap.php';
+32
View File
@@ -0,0 +1,32 @@
<?php
/**
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
* 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.
*/
require_once 'init.php';
use Core\Models\MQ;
(new MQ())->setCheckDuplicates(false)->setPriority(9)
->setAttempts(2)
->createTask(
'Core\MQTasks',
'getStory',
[]
);
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* Copyright (c) 2022 Roman Grinko <rsgrinko@gmail.com>
* 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.
*/
require_once 'init.php';
exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1');
+7 -2
View File
@@ -30,6 +30,11 @@
use Core\Models\MQ;
$fromPostId = $argv[1];
//sleep(5);
(new MQ())->setPriority(9)->setAttempts(3)->createTask('Core\MQTasks', 'getStory', [$fromPostId]);
(new MQ())->setPriority(9)
->setAttempts(2)
->createTask(
'Core\MQTasks',
'getStory',
[$fromPostId]
);