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 <?php
date_default_timezone_set('Europe/Moscow'); date_default_timezone_set('Europe/Moscow');
@ini_set('display_errors', TRUE); @ini_set('display_errors', TRUE);
@ini_set('html_errors', TRUE); @ini_set('html_errors', TRUE);
@ini_set('error_reporting', E_ALL); @ini_set('error_reporting', E_ALL);
DEFINE('EGP', TRUE); DEFINE('EGP', TRUE);
DEFINE('DIR', dirname('index.php')); DEFINE('DIR', __DIR__);
DEFINE('ROOT', DIR.'/'); DEFINE('ROOT', DIR.'/');
DEFINE('SYS', ROOT.'system/'); DEFINE('SYS', ROOT.'system/');
DEFINE('TPL', ROOT.'template/'); DEFINE('TPL', ROOT.'template/');
DEFINE('TEMP', ROOT.'temp/'); DEFINE('TEMP', ROOT.'temp/');
DEFINE('FILES', ROOT.'files/'); DEFINE('FILES', ROOT.'files/');
DEFINE('DATA', SYS.'data/'); DEFINE('DATA', SYS.'data/');
DEFINE('LIB', SYS.'library/'); DEFINE('LIB', SYS.'library/');
DEFINE('ENG', SYS.'engine/'); DEFINE('ENG', SYS.'engine/');
DEFINE('SEC', SYS.'sections/'); DEFINE('SEC', SYS.'sections/');
DEFINE('CRON', LIB.'cron/'); DEFINE('CRON', LIB.'cron/');
$start_point = $_SERVER['REQUEST_TIME']; $start_point = $_SERVER['REQUEST_TIME'];
$mcache = new Memcache; $mcache = new Memcache;
$mcache->connect('127.0.0.1', 11211) OR exit('Ошибка: не удалось создать связь с Memcache.'.PHP_EOL); $mcache->connect('127.0.0.1', 11211) OR exit('Ошибка: не удалось создать связь с Memcache.'.PHP_EOL);
// Настройки // Composer
include(DATA.'config.php'); 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); include(DATA.'config.php');
*/ include(DATA.'engine.php');
$task = $argv[2]; include(DATA.'mysql.php');
include(DATA.'params.php');
include(DATA.'engine.php'); // Проверка ключа и указания параметра
include(DATA.'mysql.php'); if($argv[1] != $cfg['cron_key'])
include(DATA.'params.php'); exit('Invalid cron key' . PHP_EOL);
$task = $argv[2];
// Библиотеки // Библиотеки
include(LIB.'sql.php'); include(LIB.'sql.php');
include(LIB.'html.php'); include(LIB.'html.php');
include(LIB.'system.php'); include(LIB.'system.php');
include(LIB.'cron.php'); include(LIB.'cron.php');
?> ?>

View file

@ -1,19 +1,27 @@
<?php <?php
if(!DEFINED('EGP')) if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404')); exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
print_r($task);
// Подгрузка трейта // Подключение filp/whoops
if(!file_exists(CRON.$task.'.php')) $whoops = new \Whoops\Run;
exit('error method'); $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 $seping = 5;
public static $process = array( public static $process = array(
'cs' => 'hlds_', 'cs' => 'hlds_',
'cssold' => 'srcds_i686', 'cssold' => 'srcds_i686',
@ -47,18 +55,13 @@ print_r($task);
for($n = 1; $n <= $num; $n+=1) for($n = 1; $n <= $num; $n+=1)
{ {
$data = ''; $data = '';
$i = 0; $i = 0;
foreach($aData as $key => $val) foreach($aData as $key => $val)
{ {
if($i == cron::$seping) if($i == cron::$seping)
break; break;
$data .= $val.' '; $data .= $val.' ';
unset($aData[$key]); unset($aData[$key]);
$i+=1; $i+=1;
} }
@ -69,9 +72,9 @@ print_r($task);
return $threads; return $threads;
} }
} }
include(CRON.$task.'.php'); include(CRON.$task.'.php');
new $task(); new $task();
?> ?>