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.
  • FEATURE AVAILABILITY STARTING FROM RELEASE 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:
    • JavaScript code can be added directly to Jobs and Monitors and is interpreted at run-time. No build cycle is required.
    • Java classes can be added that make use of of the ecosystem of available Java libraries.
  • The JobScheduler exposes its objects, methods and properties by use of the API Interface.
  • 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.

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.
  • 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.

      Pre-processing Monitor
      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:

      Windows shell job
      @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:

      Unix shell job
      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