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 " -v, --version: print version and exit.\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";
@ -49,7 +49,7 @@ if(isset($options['config'])) {
$mode = 'list';
if(isset($options['mode'])) {
if(!in_array($options['mode'], array('run', 'check', 'list'))) {
if(!in_array($options['mode'], array('run', 'dryrun', 'check', 'list'))) {
usage();
exit(1);
}
@ -71,9 +71,11 @@ foreach($tasks as $task) {
if(isset($GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()]) && is_object($taskobj = $GLOBALS['SEEDDMS_SCHEDULER']['tasks'][$task->getExtension()][$task->getTask()])) {
switch($mode) {
case "run":
case "dryrun":
if(method_exists($taskobj, 'execute')) {
if(!$task->getDisabled()) {
if(!$task->getDisabled() && $task->isDue()) {
if($user = $dms->getUserByLogin('cli_scheduler')) {
if($mode == 'run') {
if($taskobj->execute($task, $dms, $user)) {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." successful.");
$task->updateLastNextRun();
@ -81,6 +83,9 @@ foreach($tasks as $task) {
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 {
add_log_line("Execution of task ".$task->getExtension()."::".$task->getTask()." failed because of missing user 'cli_scheduler'. Task has been disabled.", PEAR_LOG_ERR);
$task->setDisabled(1);