Scope

  • By use of Scripting conditions can be added that are checked before a job will be executed.
  • Such conditions can include dynamic date calculation to check if the current date is confirmed for execution of a job.
  • Scripted conditions are considered more dynamic and flexible than configurable conditions.

Scripted Conditions

  • Scripted conditions can be added by use of Pre- and Postprocessing Monitors.
  • Each job can be assigned a number of Pre- and Postprocessing Monitors that are executed in the configured sequence.
  • The Monitor 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,
    • move Orders to the next state in a job chain if the current job should be skipped.

Date Calculation

  • Date calculation can be performed by use of JavaScript and Java:
    • JavaScript provides built-in date calculation capabilities.
    • There is always room for improvement. A good example is the date.js library that is 
    • Java extends the JavaScript capabilities if used with specific libraries for date calculation.
  • Date calculation is an intrinsic topic when considering time zones, daylight saving time, leap years etc. which is why we estimate scripting to be superior to using GUIs when it comes to more complex conditions.

Examples

  • Download: date_calculation.zip
    • Extract the archive to the hot folder in your JobScheduler installation ./config/live.
    • The archive will extract the files to a sub-folder date_calculation.
  • Assigning JavaScript libraries
    • The following examples make use of JavaScript with the date.js library that can be included with the preprocessing monitors as in the following screenshot.
    • You could use any JavaScript language capabilities or libaries of your own.

Run a job on the first week of each month

  • The standard job configuration as offered by JOE allows to specify either specific days, e.g. first Monday of a month, or specific dates, e.g. 1st to 7th.
  • In order to apply both restrictions a scripted condition like this can be used:

    Preprocessing Monitor for job1 in job_chain1
    function spooler_process_before() {
    
        // check time slot for the first week of a month
        var isJobRunEnabled = ( Date.today().getDate() <= 7 );
        if ( isJobRunEnabled ) {
            var weekdayOffset = Date.parse( (1900+Date.today().getYear()) + '-' + (1+Date.today().getMonth()) + '-01' ).getDay();
            isJobRunEabled = ( ( 7 - weekdayOffset - Date.today().getDay() ) >= 0 );
        }
        spooler_log.info( ".. job date check for run on first week of month: " + isJobRunEnabled );
    
        if ( !isJobRunEnabled ) {
            spooler_log.info( ".. moving order to state: next" );
    	    spooler_task.order.state = 'next';
    	}
    
    	return isJobRunEnabled;
    }

Run a job on Thursday and Friday after the 5th and  before 15th day of a month

  • The standard job configuration as offered by JOE allows to specify either specific weekdays or a range of days.
  • In order to apply both restrictions a scripted condition like this can be used:

    Preprocessing Monitor for job2 in job_chain2
    function spooler_process_before() {
    
        // check execution for current date
        var isJobRunEnabled = ( Date.today().is().thursday() || Date.today().is().friday() );
        spooler_log.info( ".. job date check for run on Thursday/Friday: " + isJobRunEnabled );
    
        if ( isJobRunEnabled ) {
            // check execution for current date after the 5th and before the 15th of month
            isJobRunEnabled = ( Date.today().getDate() > 5 && Date.today().getDate() < 15 );
            spooler_log.info( ".. job date check for run between 6th-14th of month: " + isJobRunEnabled );
        }
    
        if ( !isJobRunEnabled ) {
            spooler_log.info( ".. moving order to state: next" );
    	    spooler_task.order.state = "next";
    	}
    
    	return isJobRunEnabled;
    }

See also