Skip to content

Commit b34b1ad

Browse files
author
Till Brehm
committed
Improved cron debug script
1 parent 666d1df commit b34b1ad

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

server/cron_debug.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,25 @@
3939
$conf['server_id'] = intval($conf['server_id']);
4040

4141
// Load required base-classes
42-
$app->uses('modules,plugins,ini_parser,file,services,getconf,system,cron,functions');
42+
$app->uses('ini_parser,file,services,getconf,system,cron,functions');
4343
$app->load('libdatetime,cronjob');
4444

4545
// Path settings
4646
$path = SCRIPT_PATH . '/lib/classes/cron.d';
4747

4848
//** Get commandline options
49-
$cmd_opt = getopt('', array('cronjob::'));
49+
$cmd_opt = getopt('', array('cronjob::', 'force', 'firstrun'));
5050

5151
if(isset($cmd_opt['cronjob']) && is_file($path.'/'.$cmd_opt['cronjob'])) {
5252
// Cronjob that shell be run
5353
$cronjob_file = $cmd_opt['cronjob'];
5454
} else {
55-
die('Usage example: php cron_debug.php --cronjob=100-mailbox_stats.inc.php');
55+
echo "Usage example: php cron_debug.php --cronjob=100-mailbox_stats.inc.php [--force] [--firstrun]\n" ;
56+
echo "Available cronjobs:\n";
57+
foreach(glob($path.'/*-*.inc.php') as $cronjob) {
58+
echo basename($cronjob)."\n";
59+
}
60+
die();
5661
}
5762

5863
// Load and run the cronjob
@@ -61,8 +66,20 @@
6166
include $path . '/' . $cronjob_file;
6267
$class_name = 'cronjob_' . $name;
6368
$cronjob = new $class_name();
64-
$cronjob->run(true);
69+
70+
if(isset($cmd_opt['force'])) {
71+
$app->db->query("UPDATE `sys_cron` SET `running` = 0 WHERE `name` = ?", $class_name);
72+
}
73+
74+
$cronjob->onPrepare();
75+
$cronjob->onBeforeRun(isset($cmd_opt['firstrun']));
76+
if(!$cronjob->isRunning()) {
77+
$app->db->query("UPDATE `sys_cron` SET `running` = ? WHERE `name` = ?", ($cronjob->canBeRunInParallel() !== true ? "1" : "0"), $class_name);
78+
$cronjob->onRunJob();
79+
$cronjob->onAfterRun();
80+
$cronjob->onCompleted();
81+
}
6582

6683
die("finished.\n");
6784

68-
?>
85+
?>

0 commit comments

Comments
 (0)