74 $this->Database =
get_package(
'database' ,
'last' , __FILE__ );
75 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
77 $this->ScheduleAccess =
get_package(
'schedule::schedule_access' ,
'last' , __FILE__ );
78 $this->ScheduleAlgorithms =
get_package(
'schedule::schedule_algorithms' ,
'last' , __FILE__ );
112 function run_task( $Parameters , $CurrentIteration )
116 $this->Settings->load_settings( $Parameters );
117 if( $this->Settings->get_setting(
'cron_ping' ,
'0' ) == 1 )
119 print(
'Cron ping' );
121 return( $CurrentIteration + 1 );
124 catch( Exception $e )
152 private function call_run_task_function( $Task )
156 $Package =
get_package( $Task->package_name , $Task->package_version , __FILE__ );
158 if( $Package ===
false )
160 throw(
new Exception(
'The package "'.$Task->package_name.
'" has no script' ) );
163 $Delegate = array( $Package ,
'schedule_task' );
165 return( intval( call_user_func( $Delegate , $Task->parameters , $Task->next_iteration ) ) );
167 catch( Exception $e )
195 private function finish_task_processing( $Task , $NextIteration )
199 $IntervalField = $NextIteration == 0 ?
'time_step' :
'iteration_step';
201 $Fields = array(
'processing' ,
'next_processing_time' ,
'`count`' ,
'archived' ,
'next_iteration' );
203 0 ,
"DATE_ADD( NOW() , INTERVAL $IntervalField SECOND )" ,
'IF( `count` > 1 , `count` - 1 , 1 )' ,
204 'IF( type = 1 AND `count` = 1 , 1 , 0 )' , $NextIteration
207 $this->Database->update(
'umx_schedule' , $Fields , $Values ,
'id = '.$Task->id );
209 $this->Database->commit();
211 catch( Exception $e )
239 $NextIteration = $this->call_run_task_function( $Task );
241 $this->finish_task_processing( $Task , $NextIteration );
243 catch( Exception $e )
245 $this->Database->unlock();
246 $this->ScheduleAccess->update( $Task->id , array(
'processing' => 0 ) );
247 $this->Database->commit();
275 $this->ScheduleAccess->update( $Ids , array(
'processing' => 1 ) );
276 $this->Database->unlock();
278 foreach( $Tasks as $k => $Task )
283 catch( Exception $e )
307 $this->Database->lock( array(
'umx_schedule' ) , array(
'WRITE' ) );
309 $this->Settings->load_file( dirname( __FILE__ ).
'/conf/cf_schedule_settings' );
310 $Tasks = $this->ScheduleAlgorithms->get_tasks(
311 $this->Settings->get_setting(
'processing_tasks_count' , 10 )
314 if( isset( $Tasks[ 0 ] ) )
320 $this->Database->unlock();
323 catch( Exception $e )