1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-05-14 23:08:18 +03:00

fix cron and logger

This commit is contained in:
Mzhelskiy Maxim 2011-04-27 07:44:28 +00:00
parent f7e072ac3c
commit 20ab59b570
5 changed files with 26 additions and 15 deletions

View file

@ -113,6 +113,7 @@ $config['sys']['logs']['sql_query'] = false; // логирова
$config['sys']['logs']['sql_query_file'] = 'sql_query.log'; // файл лога SQL запросов $config['sys']['logs']['sql_query_file'] = 'sql_query.log'; // файл лога SQL запросов
$config['sys']['logs']['sql_error'] = true; // логировать или нет ошибки SQl $config['sys']['logs']['sql_error'] = true; // логировать или нет ошибки SQl
$config['sys']['logs']['sql_error_file'] = 'sql_error.log'; // файл лога ошибок SQL $config['sys']['logs']['sql_error_file'] = 'sql_error.log'; // файл лога ошибок SQL
$config['sys']['logs']['cron'] = true; // логировать или нет cron скрипты
$config['sys']['logs']['cron_file'] = 'cron.log'; // файл лога запуска крон-процессов $config['sys']['logs']['cron_file'] = 'cron.log'; // файл лога запуска крон-процессов
$config['sys']['logs']['profiler'] = false; // логировать или нет профилирование процессов $config['sys']['logs']['profiler'] = false; // логировать или нет профилирование процессов
$config['sys']['logs']['profiler_file'] = 'profiler.log'; // файл лога профилирования процессов $config['sys']['logs']['profiler_file'] = 'profiler.log'; // файл лога профилирования процессов

View file

@ -36,9 +36,10 @@ class Cron extends Object {
* *
* @var string * @var string
*/ */
protected $sProcessName='Cron'; protected $sProcessName;
public function __construct($sLockFile=null) { public function __construct($sLockFile=null) {
$this->sProcessName=get_class($this);
$this->oEngine=Engine::getInstance(); $this->oEngine=Engine::getInstance();
/** /**
* Инициализируем ядро * Инициализируем ядро
@ -63,8 +64,10 @@ class Cron extends Object {
* @return * @return
*/ */
public function Log($sMsg) { public function Log($sMsg) {
$sMsg=$this->sProcessName.': '.$sMsg; if (Config::Get('sys.logs.cron')) {
$this->oEngine->Logger_Notice($sMsg); $sMsg=$this->sProcessName.': '.$sMsg;
$this->oEngine->Logger_Notice($sMsg);
}
} }
/** /**
@ -129,5 +132,9 @@ class Cron extends Object {
public function Client(){ public function Client(){
throw new Exception('Call undefined client function'); throw new Exception('Call undefined client function');
} }
public function __call($sName,$aArgs) {
return $this->oEngine->_CallModule($sName,$aArgs);
}
} }
?> ?>

View file

@ -63,6 +63,12 @@ class ModuleLogger extends Module {
* @var int * @var int
*/ */
protected $iSizeForRotate=1000000; protected $iSizeForRotate=1000000;
/**
* Случайное число
*
* @var unknown_type
*/
protected $iRandom;
/** /**
@ -72,6 +78,7 @@ class ModuleLogger extends Module {
public function Init() { public function Init() {
$this->sPathLogs=Config::Get('path.root.server').'/logs/'; $this->sPathLogs=Config::Get('path.root.server').'/logs/';
$this->SetFileName(Config::Get('sys.logs.file')); $this->SetFileName(Config::Get('sys.logs.file'));
$this->iRandom=rand(1000,9999);
} }
/** /**
@ -199,6 +206,7 @@ class ModuleLogger extends Module {
*/ */
$msgOut ='['.date("Y-m-d H:i:s").']'; $msgOut ='['.date("Y-m-d H:i:s").']';
$msgOut.='['.getmypid().']'; $msgOut.='['.getmypid().']';
$msgOut.='['.$this->iRandom.']';
$msgOut.='['.$this->logLevel[$key].']'; $msgOut.='['.$this->logLevel[$key].']';
$msgOut.='['.$msg.']'; $msgOut.='['.$msg.']';
/** /**

View file

@ -14,7 +14,6 @@
* *
--------------------------------------------------------- ---------------------------------------------------------
*/ */
define('SYS_HACKER_CONSOLE',false);
$sDirRoot=dirname(dirname(dirname(__FILE__))); $sDirRoot=dirname(dirname(dirname(__FILE__)));
set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot); set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot);
@ -24,15 +23,14 @@ require_once($sDirRoot."/config/loader.php");
require_once($sDirRoot."/engine/classes/Cron.class.php"); require_once($sDirRoot."/engine/classes/Cron.class.php");
class NotifyCron extends Cron { class NotifyCron extends Cron {
protected $sProcessName='NotifyCron';
/** /**
* Выбираем пул заданий и рассылаем по ним e-mail * Выбираем пул заданий и рассылаем по ним e-mail
*/ */
public function Client() { public function Client() {
$aNotifyTasks = $this->oEngine->Notify_GetTasksDelayed(Config::Get('module.notify.per_process')); $aNotifyTasks = $this->Notify_GetTasksDelayed(Config::Get('module.notify.per_process'));
if(empty($aNotifyTasks)) { if(empty($aNotifyTasks)) {
print PHP_EOL."No tasks are found."; $this->Log("No tasks are found.");
return; return;
} }
/** /**
@ -40,14 +38,14 @@ class NotifyCron extends Cron {
*/ */
$aArrayId=array(); $aArrayId=array();
foreach ($aNotifyTasks as $oTask) { foreach ($aNotifyTasks as $oTask) {
$this->oEngine->Notify_SendTask($oTask); $this->Notify_SendTask($oTask);
$aArrayId[]=$oTask->getTaskId(); $aArrayId[]=$oTask->getTaskId();
} }
print PHP_EOL."Send notify: ".count($aArrayId); $this->Log("Send notify: ".count($aArrayId));
/** /**
* Удаляем отработанные задания * Удаляем отработанные задания
*/ */
$this->oEngine->Notify_DeleteTaskByArrayId($aArrayId); $this->Notify_DeleteTaskByArrayId($aArrayId);
} }
} }

View file

@ -14,7 +14,6 @@
* *
--------------------------------------------------------- ---------------------------------------------------------
*/ */
define('SYS_HACKER_CONSOLE',false);
$sDirRoot=dirname(dirname(dirname(__FILE__))); $sDirRoot=dirname(dirname(dirname(__FILE__)));
set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot); set_include_path(get_include_path().PATH_SEPARATOR.$sDirRoot);
@ -24,19 +23,17 @@ require_once($sDirRoot."/config/loader.php");
require_once($sDirRoot."/engine/classes/Cron.class.php"); require_once($sDirRoot."/engine/classes/Cron.class.php");
class TemplateCacheCleanCron extends Cron { class TemplateCacheCleanCron extends Cron {
protected $sProcessName='TemplateCacheCleanCron';
/** /**
* Находим все кеш-файлы js и css и удаляем их с сервера * Находим все кеш-файлы js и css и удаляем их с сервера
*/ */
public function Client() { public function Client() {
$sDir = Config::Get('path.smarty.cache');
/** /**
* Выбираем все файлы кеша * Выбираем все файлы кеша
*/ */
$aFiles = glob($sDir. DIRECTORY_SEPARATOR ."*.{css,js}", GLOB_BRACE); $aFiles = glob(Config::Get('path.smarty.cache'). DIRECTORY_SEPARATOR ."*\*.{css,js}", GLOB_BRACE);
if (!$aFiles) $aFiles=array(); if (!$aFiles) $aFiles=array();
print PHP_EOL."Cache files count: ".count($aFiles); $this->Log("Cache files count: ".count($aFiles));
foreach ($aFiles as $sFilePath) { foreach ($aFiles as $sFilePath) {
@unlink($sFilePath); @unlink($sFilePath);