system cron
This commit is contained in:
parent
6f06fd22e3
commit
29738f079a
@ -27,7 +27,10 @@ class api_system extends api_login{
|
||||
return \SYSTEM\SECURITY\Security::check($rightid);}
|
||||
public static function call_account_action_create($username, $password_sha, $email, $locale){
|
||||
return \SYSTEM\SECURITY\Security::create($username, $password_sha, $email, $locale);}*/
|
||||
|
||||
|
||||
public static function call_cron(){
|
||||
return \SYSTEM\CRON\cron::run();}
|
||||
|
||||
public static function call_locale($request,$lang){
|
||||
return \SYSTEM\LOG\JsonResult::toString(\SYSTEM\locale::getStrings($request, $lang));}
|
||||
|
||||
@ -37,5 +40,5 @@ class api_system extends api_login{
|
||||
public static function static__lang($lang){
|
||||
\SYSTEM\locale::set($lang);}
|
||||
public static function static__result($result){
|
||||
\SYSTEM\CONFIG\config::set(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_RESULT, $result);}
|
||||
\SYSTEM\CONFIG\config::set(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_RESULT, $result);}
|
||||
}
|
||||
@ -26,14 +26,12 @@ require_once dirname(__FILE__).'/system/autoload.php';
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/db/qq','SYSTEM\DB');
|
||||
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/security','SYSTEM\SECURITY');
|
||||
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/config','SYSTEM\CONFIG');
|
||||
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/cache','SYSTEM\CACHE');
|
||||
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/sai','SYSTEM\SAI');
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/docu','SYSTEM\DOCU');
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/files','SYSTEM\FILES');
|
||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/cron','SYSTEM\CRON');
|
||||
|
||||
require_once dirname(__FILE__).'/lib/autoload.inc.php';
|
||||
require_once dirname(__FILE__).'/docu/register_sys_docu.php';
|
||||
|
||||
41
cron/cron.php
Normal file
41
cron/cron.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace SYSTEM\CRON;
|
||||
|
||||
class cron {
|
||||
private static function check($cron){
|
||||
if( !\class_exists($cron) ||
|
||||
!\is_array($parents = \class_parents($cron)) ||
|
||||
!\array_search('SYSTEM\CRON\cronjob', $parents)){
|
||||
return false;}
|
||||
return true;}
|
||||
|
||||
public static function run(){
|
||||
$crons = \SYSTEM\DBD\SYS_CRON_LIST::QQ();
|
||||
while($cron = $crons->next()){
|
||||
//check module
|
||||
if(!self::check($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS])){
|
||||
self::status($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS], \SYSTEM\CRON\cronstatus::CRON_STATUS_FAIL_CLASS);
|
||||
continue;}
|
||||
//time to execute?
|
||||
if(!\SYSTEM\CRON\crontime::check_now( time($cron[\SYSTEM\DBD\system_cron::FIELD_LAST_RUN]),
|
||||
$cron[\SYSTEM\DBD\system_cron::FIELD_MIN],
|
||||
$cron[\SYSTEM\DBD\system_cron::FIELD_HOUR],
|
||||
$cron[\SYSTEM\DBD\system_cron::FIELD_DAY],
|
||||
$cron[\SYSTEM\DBD\system_cron::FIELD_DAY_WEEK],
|
||||
$cron[\SYSTEM\DBD\system_cron::FIELD_MONTH])){
|
||||
continue;}
|
||||
//Status is ok?
|
||||
if($cron[\SYSTEM\DBD\system_cron::FIELD_STATUS] != \SYSTEM\CRON\cronstatus::CRON_STATUS_SUCCESFULLY){
|
||||
new \SYSTEM\LOG\CRON('Cron for Class '.$cron[\SYSTEM\DBD\system_cron::FIELD_CLASS].' could not execute cuz Status aint good: '. \SYSTEM\CRON\cronstatus::decode($cron[\SYSTEM\DBD\system_cron::FIELD_STATUS]));
|
||||
continue;}
|
||||
//set running
|
||||
self::status($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS], \SYSTEM\CRON\cronstatus::CRON_STATUS_RUNNING);
|
||||
self::status($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS], call_user_func(array($cron[\SYSTEM\DBD\system_cron::FIELD_CLASS],'run')));
|
||||
}
|
||||
return \SYSTEM\LOG\JsonResult::ok();
|
||||
}
|
||||
|
||||
private static function status($class, $status){
|
||||
new \SYSTEM\LOG\CRON('Cron Status for Class '.$class.' updated to: '. \SYSTEM\CRON\cronstatus::decode($status));
|
||||
return \SYSTEM\DBD\SYS_CRON_UPD::QI(array($status,time(),$class));}
|
||||
}
|
||||
7
cron/cronjob.php
Normal file
7
cron/cronjob.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
namespace SYSTEM\CRON;
|
||||
|
||||
class cronjob {
|
||||
public static function run(){
|
||||
new \RuntimeException("Unimplemented!");}
|
||||
}
|
||||
9
cron/cronjobtest.php
Normal file
9
cron/cronjobtest.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace SYSTEM\CRON;
|
||||
|
||||
class cronjobtest extends cronjob {
|
||||
public static function run(){
|
||||
new \SYSTEM\LOG\WARNING("Unimplemented!");
|
||||
return \SYSTEM\CRON\cronstatus::CRON_STATUS_SUCCESFULLY;
|
||||
}
|
||||
}
|
||||
29
cron/cronstatus.php
Normal file
29
cron/cronstatus.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace SYSTEM\CRON;
|
||||
|
||||
class cronstatus {
|
||||
const CRON_STATUS_SUCCESFULLY = 0;
|
||||
const CRON_STATUS_RUNNING = 1;
|
||||
const CRON_STATUS_FAIL = 2;
|
||||
const CRON_STATUS_FAIL_CLASS = 3;
|
||||
|
||||
const CRON_STATUS_USER_STATES = 99;
|
||||
|
||||
public static function decode($status){
|
||||
switch($status){
|
||||
case self::CRON_STATUS_SUCCESFULLY:
|
||||
$status = 'CRON_STATUS_SUCCESFULLY';
|
||||
break;
|
||||
case self::CRON_STATUS_RUNNING:
|
||||
$status = 'CRON_STATUS_RUNNING';
|
||||
break;
|
||||
case self::CRON_STATUS_FAIL:
|
||||
$status = 'CRON_STATUS_FAIL';
|
||||
break;
|
||||
case self::CRON_STATUS_FAIL_CLASS:
|
||||
$status = 'CRON_STATUS_FAIL_CLASS';
|
||||
break;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
56
cron/crontime.php
Normal file
56
cron/crontime.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace SYSTEM\CRON;
|
||||
|
||||
//http://coderzone.org/library/PHP-PHP-Cron-Parser-Class_1084.htm
|
||||
class crontime {
|
||||
public static function next($base_time,$min,$hour,$day,$day_week,$month){
|
||||
list( $now_min, $now_hour, $now_day, $now_month, $now_day_week ) = preg_split( "/ /", date("i H d n N", $base_time ) );
|
||||
list( $next_min, $next_hour, $next_day, $next_month, $next_year) = preg_split( "/ /", date("i H d n Y", $base_time ) );
|
||||
if($month){
|
||||
if($month < $now_month){ $next_year += 1;}
|
||||
$next_month = $month;}
|
||||
if($day){
|
||||
if($day < $now_day){ $next_month += 1;}
|
||||
$next_day = $day;}
|
||||
if($hour){
|
||||
if($hour < $now_hour){ $next_day += 1;}
|
||||
$next_hour = $hour;}
|
||||
if($min){
|
||||
if($min < $now_min){ $next_hour += 1;}
|
||||
$next_min = $min;}
|
||||
if($day_week){
|
||||
$day_week = $day_week % 6; // 7 and 0 both mean Sunday
|
||||
$now_day_week = $now_day_week % 6; // 7 and 0 both mean Sunday
|
||||
$next_day += abs($day_week - $now_day_week);}
|
||||
return mktime($next_hour, $next_min, 0, $next_month, $next_day, $next_year);
|
||||
}
|
||||
public static function last($base_time,$min,$hour,$day,$day_week,$month){
|
||||
list( $now_min, $now_hour, $now_day, $now_month, $now_day_week ) = preg_split( "/ /", date("i H d n N", $base_time ) );
|
||||
list( $last_min, $last_hour, $last_day, $last_month, $last_year) = preg_split( "/ /", date("i H d n Y", $base_time ) );
|
||||
if($month){
|
||||
if($month > $now_month){ $last_year -= 1;}
|
||||
$last_month = $month;}
|
||||
if($day){
|
||||
if($day > $now_day){ $last_month -= 1;}
|
||||
$last_day = $day;}
|
||||
if($hour){
|
||||
if($hour > $now_hour){ $last_day -= 1;}
|
||||
$last_hour = $hour;}
|
||||
if($min){
|
||||
if($min > $now_min){ $last_hour -= 1;}
|
||||
$last_min = $min;}
|
||||
if($day_week){
|
||||
$day_week = $day_week % 6; // 7 and 0 both mean Sunday
|
||||
$now_day_week = $now_day_week % 6; // 7 and 0 both mean Sunday
|
||||
$last_day -= abs($day_week - $now_day_week);}
|
||||
return mktime($last_hour, $last_min, 0, $last_month, $last_day, $last_year);
|
||||
}
|
||||
public static function check($base_time,$last_run,$min,$hour,$day,$day_week,$month){
|
||||
return crontime::next($last_run, $min, $hour, $day, $day_week, $month) < $base_time ? true : false;}
|
||||
public static function next_now($min,$hour,$day,$day_week,$month){
|
||||
self::next(time(),$min,$hour,$day,$day_week,$month);}
|
||||
public static function last_now($min,$hour,$day,$day_week,$month){
|
||||
return self::last(time(),$min,$hour,$day,$day_week,$month);}
|
||||
public static function check_now($last_run,$min,$hour,$day,$day_week,$month){
|
||||
return self::check(time(),$last_run,$min,$hour,$day,$day_week,$month);}
|
||||
}
|
||||
11
dbd/qq/SYS_CRON_LIST.php
Normal file
11
dbd/qq/SYS_CRON_LIST.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class SYS_CRON_LIST extends \SYSTEM\DB\QQ {
|
||||
protected static function query(){
|
||||
return new \SYSTEM\DB\QQuery(get_class(),
|
||||
//pg
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_cron::NAME_PG.';',
|
||||
//mys
|
||||
'SELECT * FROM '.\SYSTEM\DBD\system_cron::NAME_MYS.';'
|
||||
);}}
|
||||
11
dbd/qq/SYS_CRON_UPD.php
Normal file
11
dbd/qq/SYS_CRON_UPD.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class SYS_CRON_UPD extends \SYSTEM\DB\QP {
|
||||
protected static function query(){
|
||||
return new \SYSTEM\DB\QQuery(get_class(),
|
||||
//pg
|
||||
'UPDATE '.\SYSTEM\DBD\system_cron::NAME_PG.' SET '.\SYSTEM\DBD\system_cron::FIELD_STATUS.' = $1,'.\SYSTEM\DBD\system_cron::FIELD_LAST_RUN.' = $2 WHERE '.\SYSTEM\DBD\system_cron::FIELD_CLASS.' = $3;',
|
||||
//mys
|
||||
'UPDATE '.\SYSTEM\DBD\system_cron::NAME_MYS.' SET '.\SYSTEM\DBD\system_cron::FIELD_STATUS.' = ?,'.\SYSTEM\DBD\system_cron::FIELD_LAST_RUN.' = FROM_UNIXTIME(?) WHERE '.\SYSTEM\DBD\system_cron::FIELD_CLASS.' = ?;'
|
||||
);}}
|
||||
18
dbd/tbl/system_cron.php
Normal file
18
dbd/tbl/system_cron.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace SYSTEM\DBD;
|
||||
|
||||
class system_cron {
|
||||
const NAME_PG = 'system.cron';
|
||||
const NAME_MYS = 'system_cron';
|
||||
|
||||
const FIELD_CLASS = 'class';
|
||||
const FIELD_MIN = 'min';
|
||||
const FIELD_HOUR = 'hour';
|
||||
const FIELD_DAY = 'day';
|
||||
const FIELD_DAY_WEEK = 'day_week';
|
||||
const FIELD_MONTH = 'month';
|
||||
const FIELD_DAY_MONTH = 'day_month';
|
||||
const FIELD_LAST_RUN = 'last_run';
|
||||
const FIELD_STATUS = 'status';
|
||||
}
|
||||
@ -154,7 +154,9 @@
|
||||
* E: 00:01:33: mmh ?
|
||||
|
||||
- ##### A: 00:01:38: s_algo
|
||||
|
||||
- ##### A: 00:01:45: so soll die klasse heißen
|
||||
|
||||
- ##### A: 00:01:56: s_algo.php
|
||||
|
||||
* ##### * E: 00:01:58: ja so heißt sie
|
||||
|
||||
5
log/exceptions/CRON.php
Normal file
5
log/exceptions/CRON.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
namespace SYSTEM\LOG;
|
||||
|
||||
class CRON extends \SYSTEM\LOG\INFO{}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user