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

@ -6,7 +6,7 @@
@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/');
@ -23,18 +23,23 @@
$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
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');
// Настройки // Настройки
include(DATA.'config.php'); include(DATA.'config.php');
/*if($argv[1] != $cfg['cron_key'])
exit('error key.'.PHP_EOL);
*/
$task = $argv[2];
include(DATA.'engine.php'); include(DATA.'engine.php');
include(DATA.'mysql.php'); include(DATA.'mysql.php');
include(DATA.'params.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.'sql.php');
include(LIB.'html.php'); include(LIB.'html.php');

View file

@ -1,11 +1,20 @@
<?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
$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);
// Подгрузка трейта // Подгрузка трейта
if(!file_exists(CRON.$task.'.php')) if(!file_exists(CRON.$task.'.php'))
exit('error method'); exit('Invalid cron method' . PHP_EOL);
$device = '!mobile'; $device = '!mobile';
$user = array('id' => 0, 'group' => 'admin'); $user = array('id' => 0, 'group' => 'admin');
@ -13,7 +22,6 @@ print_r($task);
class cron 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;
} }