add mode 'dryrun', actually check if a task is due

This commit is contained in:
Uwe Steinmann 2020-05-19 17:49:32 +02:00
parent 98374b513d
commit 2bd75c6d1f

View File

@ -19,7 +19,7 @@ function usage() { /* {{{ */
echo " -h, --help: print usage information and exit.\n"; echo " -h, --help: print usage information and exit.\n";
echo " -v, --version: print version and exit.\n"; echo " -v, --version: print version and exit.\n";
echo " --config: set alternative config file.\n"; echo " --config: set alternative config file.\n";
echo " --mode: set mode of operation (run, check, list).\n"; echo " --mode: set mode of operation (run, dryrun, check, list).\n";
} /* }}} */ } /* }}} */
$version = "0.0.1"; $version = "0.0.1";
@ -49,7 +49,7 @@ if(isset($options['config'])) {
$mode = 'list'; $mode = 'list';
if(isset($options['mode'])) { if(isset($options['mode'])) {
if(!in_array($options['mode'], array('run', 'check', 'list'))) { if(!in_array($options['mode'], array('run', 'dryrun', 'check', 'list'))) {
usage(); usage();
exit(1); exit(1);
} }
@ -71,15 +71,20 @@ foreach($tasks as $task) {
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()])) { if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()])) {
switch($mode) { switch($mode) {
case "run": case "run":
case "dryrun":
if(method_exists($taskobj, 'execute')) { if(method_exists($taskobj, 'execute')) {
if(!$task->getDisabled()) { if(!$task->getDisabled() && $task->isDue()) {
if($user = $dms->getUserByLogin('cli_scheduler')) { if($user = $dms->getUserByLogin('cli_scheduler')) {
if($taskobj->execute($task, $dms, $user)) { if($mode == 'run') {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful."); if($taskobj->execute($task, $dms, $user)) {
$task->updateLastNextRun(); add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
} else { $task->updateLastNextRun();
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR); } else {
$task->setDisabled(1); add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed, task has been disabled.", PEAR_LOG_ERR);
$task->setDisabled(1);
}
} elseif($mode == 'dryrun') {
echo "Running ".$task->getExtension()."::".$task->getTask()."\n";
} }
} else { } else {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed because of missing user 'cli_scheduler'. Task has been disabled.", PEAR_LOG_ERR); add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed because of missing user 'cli_scheduler'. Task has been disabled.", PEAR_LOG_ERR);