Table of Contents |
---|
Scope
- By use of Scripting the last execution date of a job can be retrieved from the job history.
- Such information can be exposed as job parameter to the current job.
Display feature availability StartingFromRelease 1.10.1
Scripting
- Scripting can be added by use of Pre- and Postprocessing Scripts.
- Each job can be assigned a number of Pre- and Postprocessing scripts that are executed in the configured sequence.
- The scripts can include
- Java classes
- JavaScript code
- Scripted conditions are a powerful means for flexibility:
- The JobScheduler exposes its objects, methods and properties by use of the API Interface.
- Find details and examples with the Reference Documentation.
- Scripted conditions can be applied by implementing a
spooler_process_before()
function for a preprocessor monitor with jobs in a job chain that will- return the value
true
if the job should start, - return the value
false
if the job should not start.
- return the value
Example
- 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 xml 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 xml 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}"
See also
- How to check the job history for previous job runs
- How to add conditions for job execution with date calculation
...