Merge pull request #62 from EngineGPDev/Added-cron-task-execution-logs

Added cron task execution logs
This commit is contained in:
Sergei Solovev 2023-04-28 23:23:12 +03:00 committed by GitHub
commit de6a5fb203
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 92 deletions

View file

@ -1,43 +1,48 @@
<?php
date_default_timezone_set('Europe/Moscow');
date_default_timezone_set('Europe/Moscow');
@ini_set('display_errors', TRUE);
@ini_set('html_errors', TRUE);
@ini_set('error_reporting', E_ALL);
@ini_set('display_errors', TRUE);
@ini_set('html_errors', TRUE);
@ini_set('error_reporting', E_ALL);
DEFINE('EGP', TRUE);
DEFINE('DIR', dirname('index.php'));
DEFINE('ROOT', DIR.'/');
DEFINE('SYS', ROOT.'system/');
DEFINE('TPL', ROOT.'template/');
DEFINE('TEMP', ROOT.'temp/');
DEFINE('FILES', ROOT.'files/');
DEFINE('DATA', SYS.'data/');
DEFINE('LIB', SYS.'library/');
DEFINE('ENG', SYS.'engine/');
DEFINE('SEC', SYS.'sections/');
DEFINE('CRON', LIB.'cron/');
DEFINE('EGP', TRUE);
DEFINE('DIR', __DIR__);
DEFINE('ROOT', DIR.'/');
DEFINE('SYS', ROOT.'system/');
DEFINE('TPL', ROOT.'template/');
DEFINE('TEMP', ROOT.'temp/');
DEFINE('FILES', ROOT.'files/');
DEFINE('DATA', SYS.'data/');
DEFINE('LIB', SYS.'library/');
DEFINE('ENG', SYS.'engine/');
DEFINE('SEC', SYS.'sections/');
DEFINE('CRON', LIB.'cron/');
$start_point = $_SERVER['REQUEST_TIME'];
$start_point = $_SERVER['REQUEST_TIME'];
$mcache = new Memcache;
$mcache->connect('127.0.0.1', 11211) OR exit('Ошибка: не удалось создать связь с Memcache.'.PHP_EOL);
$mcache = new Memcache;
$mcache->connect('127.0.0.1', 11211) OR exit('Ошибка: не удалось создать связь с Memcache.'.PHP_EOL);
// Настройки
include(DATA.'config.php');
// Composer
if (!file_exists(ROOT.'vendor/autoload.php')) {
die('Please <a href="https://getcomposer.org/download/" target="_blank" rel="noreferrer" style="color:#0a25bb;">install composer</a> and run <code style="background:#222;color:#00e01f;padding:2px 6px;border-radius:3px;">composer install</code>');
}
require(ROOT.'vendor/autoload.php');
/*if($argv[1] != $cfg['cron_key'])
exit('error key.'.PHP_EOL);
*/
$task = $argv[2];
// Настройки
include(DATA.'config.php');
include(DATA.'engine.php');
include(DATA.'mysql.php');
include(DATA.'params.php');
include(DATA.'engine.php');
include(DATA.'mysql.php');
include(DATA.'params.php');
// Проверка ключа и указания параметра
if($argv[1] != $cfg['cron_key'])
exit('Invalid cron key' . PHP_EOL);
$task = $argv[2];
// Библиотеки
include(LIB.'sql.php');
include(LIB.'html.php');
include(LIB.'system.php');
include(LIB.'cron.php');
// Библиотеки
include(LIB.'sql.php');
include(LIB.'html.php');
include(LIB.'system.php');
include(LIB.'cron.php');
?>

View file

@ -1,77 +1,80 @@
<?php
if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
print_r($task);
if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
// Подгрузка трейта
if(!file_exists(CRON.$task.'.php'))
exit('error method');
// Подключение filp/whoops
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
// логи в файл
$loggingInFile = new \Whoops\Handler\PlainTextHandler();
$loggingInFile->loggerOnly(true);
$loggingInFile->setLogger((new \Monolog\Logger('EngineGP', [(new \Monolog\Handler\StreamHandler(ROOT . '/logs/cron.log'))->setFormatter((new \Monolog\Formatter\LineFormatter(null, null, true)))])));
$whoops->pushHandler($loggingInFile);
$device = '!mobile';
$user = array('id' => 0, 'group' => 'admin');
// Подгрузка трейта
if(!file_exists(CRON.$task.'.php'))
exit('Invalid cron method' . PHP_EOL);
class cron
$device = '!mobile';
$user = array('id' => 0, 'group' => 'admin');
class cron
{
public static $seping = 5;
public static $process = array(
'cs' => 'hlds_',
'cssold' => 'srcds_i686',
'css' => 'srcds_',
'csgo' => 'srcds_',
'samp' => 'samp',
'crmp' => 'samp',
'mta' => 'mta',
'mc' => 'java'
);
public static $quakestat = array(
'cs' => 'a2s',
'cssold' => 'a2s',
'css' => 'a2s',
'csgo' => 'a2s',
'mta' => 'eye'
);
public static $admins_file = array(
'cs' => 'cstrike/addons/amxmodx/configs/users.ini',
'cssold' => 'cstrike/addons/sourcemod/configs/admins_simple.ini',
'css' => 'cstrike/addons/sourcemod/configs/admins_simple.ini',
'csgo' => 'csgo/addons/sourcemod/configs/admins_simple.ini'
);
public static function thread($num, $type, $aData)
{
public static $seping = 5;
$threads = array();
public static $process = array(
'cs' => 'hlds_',
'cssold' => 'srcds_i686',
'css' => 'srcds_',
'csgo' => 'srcds_',
'samp' => 'samp',
'crmp' => 'samp',
'mta' => 'mta',
'mc' => 'java'
);
public static $quakestat = array(
'cs' => 'a2s',
'cssold' => 'a2s',
'css' => 'a2s',
'csgo' => 'a2s',
'mta' => 'eye'
);
public static $admins_file = array(
'cs' => 'cstrike/addons/amxmodx/configs/users.ini',
'cssold' => 'cstrike/addons/sourcemod/configs/admins_simple.ini',
'css' => 'cstrike/addons/sourcemod/configs/admins_simple.ini',
'csgo' => 'csgo/addons/sourcemod/configs/admins_simple.ini'
);
public static function thread($num, $type, $aData)
for($n = 1; $n <= $num; $n+=1)
{
$threads = array();
for($n = 1; $n <= $num; $n+=1)
$data = '';
$i = 0;
foreach($aData as $key => $val)
{
$data = '';
$i = 0;
foreach($aData as $key => $val)
{
if($i == cron::$seping)
break;
if($i == cron::$seping)
break;
$data .= $val.' ';
unset($aData[$key]);
$i+=1;
}
$aData = array_values($aData);
$threads[] = $type.' '.substr($data, 0, -1);
}
return $threads;
$aData = array_values($aData);
$threads[] = $type.' '.substr($data, 0, -1);
}
return $threads;
}
}
include(CRON.$task.'.php');
include(CRON.$task.'.php');
new $task();
new $task();
?>