partial #2816 - cron - logs

This commit is contained in:
Daniel Camargo 2014-05-27 20:30:35 -03:00
parent 6686180800
commit 6701018fa4

View File

@ -20,6 +20,7 @@ class Crunchbutton_Cron_Log extends Cana_Table {
}
public static function start(){
$crons = Crunchbutton_Cron_Log::q( "SELECT * FROM cron_log WHERE `interval` != '' AND interval_unity > 0" );
if( $crons->count() ){
Log::debug( [ 'type' => 'cron-jobs', 'method' => 'start', 'desc' => 'working with ' . $crons->count() . ' cron jobs' ] );
@ -44,9 +45,9 @@ class Crunchbutton_Cron_Log extends Cana_Table {
$job = $this;
// Timeout to run it async
Cana::timeout( function() use( $job ) {
// Cana::timeout( function() use( $job ) {
$job->go();
} );
// } );
}
}
@ -128,13 +129,14 @@ class Crunchbutton_Cron_Log extends Cana_Table {
}
public function go(){
$this->log( 'go', $this->class );
if( class_exists( $this->class ) ){
$job = new $this->class;
if( is_a( $job, 'Crunchbutton_Cron_Log' ) ){
if( method_exists( $job, 'run' ) ){
$this->log( 'run', 'running' );
$job->id_cron_log = $this->id_cron_log;
$job->run();
$this->log( 'go', $this->class . ' called run' );
} else {
$this->log( 'run', 'error: ' . $this->class . ' doesnt have the method run' );
}
@ -182,6 +184,6 @@ class Crunchbutton_Cron_Log extends Cana_Table {
public function log( $method, $message ){
$data = [ 'type' => 'cron-jobs', 'method' => $method, 'message' => $message, 'desc' => $this->description, 'id_cron_log' => $this->id_cron_log ];
Log::debug( $data );
echo $method . ':' $message . "\n";
}
}