You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

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 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 are applied by implementing a spooler_process_before() method for jobs in a ob 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.
    • 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

The following examples make use of the date.js library that is included with the monitor scripts as in the following screenshot:

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 use both restrictions a scripted condition like this would apply:

    function spooler_process_before() {
        var isJobRunEnabled = true;
    
        if ( isJobRunEnabled ) {
            // check execution for the first week of a month
            if ( Date.today().getDay() <= 7 ) {
                var weekdayOffset = Date.parse( (1900+Date.today().getYear()) + '-' + (1+Date.today().getMonth()) + '-01' ).getDay();
                isJobRunEabled = ( ( 7 - weekdayOffset - Date.today().getDay() ) >= 0 );
                spooler_log.info( "result = (7 - weekdayOffset [" + weekdayOffset + "] - Date.today().getDay() [" + Date.today().getDay() + "]) >= 0 : " + isJobRunEnabled );
            }
            spooler_log.info( ".. job date check for run on first week of month: " + isJobRunEnabled );
        }
    
        if ( !isJobRunEnabled ) {
    	    spooler_task.order.state = "job_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 use both restrictions a scripted condition like this would apply:

    function spooler_process_before() {
        var isJobRunEnabled = true;
    
        if ( isJobRunEnabled ) {
            // check execution for current date
            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 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_task.order.state = "job_next";
    	}
    
    	return isJobRunEnabled;
    }

See also

 

  • No labels