[*] переработана система работы с кроновыми заданиями. Теперь добавить задание проще простого и не нужно постоянно лазить в кронтаб
This commit is contained in:
1 parent
c54cb5f9e1
commit
b4f506cc1f
5 files changed
+103
-37
No files matched your search
+10
-35
@@ -23,45 +23,20 @@
|
|||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
use Core\Helpers\Log;
|
use Core\Helpers\Log;
|
||||||
use Core\Models\MQ;
|
|
||||||
|
|
||||||
if (empty($_SERVER['DOCUMENT_ROOT'])) {
|
if (empty($_SERVER['DOCUMENT_ROOT'])) {
|
||||||
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/..';
|
$_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/..';
|
||||||
}
|
}
|
||||||
require_once __DIR__ . '/bootstrap.php';
|
require_once __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
// Запускаем воркер диспетчера очереди
|
$tasksDir = __DIR__ . '/cronTasks/';
|
||||||
exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1');
|
$list = scandir($tasksDir);
|
||||||
|
$logFileName = 'cron.log';
|
||||||
//$result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO');
|
foreach ($list as $file) {
|
||||||
|
if (in_array($file, ['.', '..', 'init.php'], true)) {
|
||||||
// Попытка получения валюты сайта за ежедневные авторизации
|
continue;
|
||||||
$cookieFile = $_SERVER['DOCUMENT_ROOT'] . '/uploads/visaviCookie.txt';
|
}
|
||||||
$logFileName = 'visavi.log';
|
$command = '(php -f ' . $tasksDir . $file . ' & ) >> /dev/null 2>&1';
|
||||||
|
Log::logToFile($command, $logFileName);
|
||||||
if (!file_exists($cookieFile) || time() - @filectime($cookieFile) > 60 * 60 * 23) {
|
exec($command);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
@@ -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';
|
||||||
@@ -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',
|
||||||
|
[]
|
||||||
|
);
|
||||||
@@ -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');
|
||||||
@@ -30,6 +30,11 @@
|
|||||||
|
|
||||||
use Core\Models\MQ;
|
use Core\Models\MQ;
|
||||||
$fromPostId = $argv[1];
|
$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]
|
||||||
|
);
|
||||||
Reference in new issue
Block a user