@@ -51,19 +51,39 @@ function cfip() { return (@defined('SECURITY')) ? 1 : 0; }
51
51
require_once (BASEPATH . '../include/bootstrap.php ' );
52
52
require_once (BASEPATH . '../include/version.inc.php ' );
53
53
54
+ // Load 3rd party logging library for running crons
55
+ $ log = KLogger::instance ( BASEPATH . '../logs/ ' . $ cron_name , KLogger::INFO );
56
+
54
57
// Command line switches
55
58
array_shift ($ argv );
56
- foreach ($ argv as $ option ) {
59
+ foreach ($ argv as $ index => $ option ) {
57
60
switch ($ option ) {
58
61
case '-f ' :
59
62
$ monitoring ->setStatus ($ cron_name . "_disabled " , "yesno " , 0 );
60
63
$ monitoring ->setStatus ($ cron_name . "_active " , "yesno " , 0 );
61
64
break ;
65
+ case '-t ' :
66
+ // When `-t TIME_IN_SEC` is specified, we ignore the cron active flag
67
+ // if the time elapsed `TIME_IN_SEC` seconds after the last job started.
68
+
69
+ // Check the next argument is the value for -t option.
70
+ if (!($ index + 1 < count ($ argv )) || // check if '-t' is not the last argument.
71
+ !(ctype_digit ($ argv [$ index + 1 ]))) { // check the next argument is numeric string
72
+ $ log ->logFatal ('Option -t requires an integer. ' );
73
+ $ monitoring ->endCronjob ($ cron_name , 'E0085 ' , 3 , true , false );
74
+ }
75
+
76
+ $ timeout = intval ($ argv [$ index + 1 ]);
77
+ $ timeElapsedFromLastStart = $ dStartTime - $ monitoring ->getLastCronStarted ($ cron_name );
78
+
79
+ if ($ timeElapsedFromLastStart > $ timeout ) {
80
+ $ log ->logWarn ("Previous cronjob ` $ cron_name` is started before than you specified by -t. Re-run forced. " );
81
+ $ monitoring ->setStatus ($ cron_name . "_active " , "yesno " , 0 );
82
+ }
83
+ break ;
62
84
}
63
85
}
64
86
65
- // Load 3rd party logging library for running crons
66
- $ log = KLogger::instance ( BASEPATH . '../logs/ ' . $ cron_name , KLogger::INFO );
67
87
$ log ->LogDebug ('Starting ' . $ cron_name );
68
88
69
89
// Load the start time for later runtime calculations for monitoring
0 commit comments