patternphpMinor
PHP Cron wrapper
Viewed 0 times
phpwrappercron
Problem
I attempt to create a reusable and scalable Cron Wrapper in PHP.
I'm at the begining of the project and I wanted have some tips/ critics / improvments to make before going too far.
The final objective is to have a complete cron wrapper which allows to lauch :
There is the main core class
```
status === false)
break;
}
if (static::$profiling)
\Nzdrm\Profiler::mark(__METHOD__.' End');
if (static::$logging)
logger('INFO', 'Nozdormu ended '.$process.'.php');
self::shut_down();
}
public static function shut_down()
{
if (static::$logging)
logger('INFO', 'Nozdormu is Shuting down.');
$mail = new \PHPmailer();
$mail->From = 'noreply@'.static::$organisation;
$mail->FromName = 'Nozdormu';
$mail->addAddress(static::$mail_recipient);
$mail->addReplyTo('noreply@'.static::$organisation, 'No-Reply');
$mail->WordWrap = 50;
if (file_exists(static::$log_folder_path.date('Y/m/d-').static::$process.'.log'))
$mail->addAttachment(static::$log_folder_path.date('Y/m/d-').static::$process.'.log');
$mail->isHTML(false);
$title = '';
$err= false;
if (file_exists(static::$log_folder_path.date('Y/m/d-').static::$process.'.log'))
{
$ftmp = file_get_contents(static::$log_folder_path.date('Y/m/d-').static::$process.'.log');
$titlechange = array('WARNING', 'ERROR','ALERT');
foreach ($titlechange AS $tc)
if (substr_count($ftmp, $tc))
{
$title = 'Cron ended with '.strtolower($tc).'(s)';
$err= true;
I'm at the begining of the project and I wanted have some tips/ critics / improvments to make before going too far.
The final objective is to have a complete cron wrapper which allows to lauch :
- 'one-shot' task (like huge DB export) from Web
- manage Crontask from a web interface or from the 'default way'
- Maybe more ;)
There is the main core class
```
status === false)
break;
}
if (static::$profiling)
\Nzdrm\Profiler::mark(__METHOD__.' End');
if (static::$logging)
logger('INFO', 'Nozdormu ended '.$process.'.php');
self::shut_down();
}
public static function shut_down()
{
if (static::$logging)
logger('INFO', 'Nozdormu is Shuting down.');
$mail = new \PHPmailer();
$mail->From = 'noreply@'.static::$organisation;
$mail->FromName = 'Nozdormu';
$mail->addAddress(static::$mail_recipient);
$mail->addReplyTo('noreply@'.static::$organisation, 'No-Reply');
$mail->WordWrap = 50;
if (file_exists(static::$log_folder_path.date('Y/m/d-').static::$process.'.log'))
$mail->addAttachment(static::$log_folder_path.date('Y/m/d-').static::$process.'.log');
$mail->isHTML(false);
$title = '';
$err= false;
if (file_exists(static::$log_folder_path.date('Y/m/d-').static::$process.'.log'))
{
$ftmp = file_get_contents(static::$log_folder_path.date('Y/m/d-').static::$process.'.log');
$titlechange = array('WARNING', 'ERROR','ALERT');
foreach ($titlechange AS $tc)
if (substr_count($ftmp, $tc))
{
$title = 'Cron ended with '.strtolower($tc).'(s)';
$err= true;
Solution
Going to try to answer my own question. So I should use :
Based on Elias comments :
Finally I realize that is the approach may be a bit outdated, and a puppet based solution would be more suitable, and this project is going to go in study case archive.
- Less
statics, and implement an interface to deal with config parameters, and just keep the most useful in attributs (logging,profilling)
- Move the mailing functionnality to her own method.
- In
\Nzdrm::initjust keep the init forlogging,profillingandlocaleconfiguration.
- Use
Exceptions
- (Minor) Comment code while coding, otherwise it's going to never be done.
Based on Elias comments :
- Use an autoloader
- Don't try to deal without a conf file and just exit with a
FATAL ERROR, so delete all default values.
Finally I realize that is the approach may be a bit outdated, and a puppet based solution would be more suitable, and this project is going to go in study case archive.
Context
StackExchange Code Review Q#36140, answer score: 3
Revisions (0)
No revisions yet.