Added cron task execution logs

This commit is contained in:
Sergei Solovev 2023-04-28 23:21:32 +03:00
parent 0b8629260e
commit 2c3dfa71a3
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,19 +1,27 @@
<?php
if(!DEFINED('EGP'))
if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
print_r($task);
// Подгрузка трейта
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',
@ -47,18 +55,13 @@ print_r($task);
for($n = 1; $n <= $num; $n+=1)
{
$data = '';
$i = 0;
foreach($aData as $key => $val)
{
if($i == cron::$seping)
break;
$data .= $val.' ';
unset($aData[$key]);
$i+=1;
}
@ -69,9 +72,9 @@ print_r($task);
return $threads;
}
}
}
include(CRON.$task.'.php');
include(CRON.$task.'.php');
new $task();
new $task();
?>