...
- Download: last_execution.zip
- Extract the archive to the hot folder in your JobScheduler installation
./config/live
. - The archive will extract the files to a sub-folder
last_execution.
- Extract the archive to the hot folder in your JobScheduler installation
The example retrieves the last execution date of the current job and adds this information as a job parameter:
The example makes use of
a pre-processing Monitor to retrieve the last execution date.
Code Block language js title Pre-processing Monitor for job1 in job_chain1 collapse true function spooler_process_before() {function spooler_process_before() { var jobHistory = new Packages.com.sos.jitl.checkrunhistory.JobHistory( spooler.delegate ); var jobHistoryInfo = jobHistory.getJobInfo( spooler_task.job.name, "100", "" ); spooler_log.info("last run completed: " + jobHistoryInfo.getLastCompleted().end ); spooler_log.info("last run completed successful: " + jobHistoryInfo.getLastCompletedSuccessful().end ); spooler_log.info("last run completed with error: " + jobHistoryInfo.getLastCompletedWithError().end ); var lastRunCompleted = jobHistoryInfo.getLastCompleted().found ? java.time.LocalDateTime.ofInstant(jobHistoryInfo.getLastCompleted().end.toInstant(), java.time.ZoneId.systemDefault() ) : ""; var lastRunCompletedSuccessful = jobHistoryInfo.getLastCompletedSuccessful().found ? java.time.LocalDateTime.ofInstant(jobHistoryInfo.getLastCompletedSuccessful().end.toInstant(), java.time.ZoneId.systemDefault() ) : ""; var lastRunCompletedWithError = jobHistoryInfo.getLastCompletedWithError().found ? java.time.LocalDateTime.ofInstant(jobHistoryInfo.getLastCompletedWithError().end.toInstant(), java.time.ZoneId.systemDefault() ) : ""; spooler_task.params.set_var( "last_run_completed", lastRunCompleted ); spooler_task.params.set_var( "last_run_completed_successful", lastRunCompletedSuccessful ); spooler_task.params.set_var( "last_run_completed_with_error", lastRunCompletedWithError ); return true; }
the Monitor makes use of the Job History to retrieve the execution date.
- Some Java date calculation is added to convert dates to an ISO 8601 format. This can be adjusted as desired.
a Windows shell job that simple outputs the parameters that have previously been added:
Code Block language xmlbash title Windows shell job for job1 in job_chain1 collapse true @echo last job run completed: %SCHEDULER_PARAM_LAST_RUN_COMPLETED% @echo last job run completed successful: %SCHEDULER_PARAM_LAST_RUN_COMPLETED_SUCCESSFUL% @echo last job run completed with error: %SCHEDULER_PARAM_LAST_RUN_COMPLETED_WITH_ERROR%
the same job would be used for Unix environments like this:
Code Block language xmlbash title Unix shell job for job1 in job_chain1 collapse true echo "last job run completed: ${SCHEDULER_PARAM_LAST_RUN_COMPLETED}" echo "last job run completed successful: ${SCHEDULER_PARAM_LAST_RUN_COMPLETED_SUCCESSFUL}" echo "last job run completed with error: ${SCHEDULER_PARAM_LAST_RUN_COMPLETED_WITH_ERROR}"
...