Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

Terminating Job successfully

There are no specifics for successful termination of a JavaScript job:

Code Block
languagejs
titleExample for implementation of JS7Job with JavaScript
linenumberstrue
class JS7Job extends js7.Job {

	processOrder(js7Step) {
    	// do some stuff  
		return;
        // ...
    }
}


Explanation:

  • No specific measures apply. As in any JavaScript function the return statement can be used to leave the processOrder() method prematurely.
  • If the return statement is not used then the job terminates successfully when leaving the processOrder() method.

Terminating Job successfully with warning

JavaScript Jobs can be configured to continue in case of warnings and to send a JS7 - Notification:

  • JavaScript Jobs can be configured to expect a number of return codes that are considered warnings.
  • Such return codes will not fail the job but will result in a notification if specified with the job.

Image Added


The implementation of the job that specifies a return code looks like this:

Code Block
languagejs
titleExample for implementation of JS7Job with JavaScript
linenumberstrue
class JS7Job extends js7.Job {

	processOrder(js7Step) {
      	// do some stuff
      
        js7Step.getLogger().warn('warning occurred');
        js7Step.getOutcome().setReturnCode(1);
		return;
    }
}


Explanation:

  • The getLogger().warn() method creates log output that qualifies as a warning.
  • The getOutcome().setReturnCode() method is used to specify a return code:
    • Setting the return code in a JavaScript job does not raise an error. 
    • Return codes can be checked in a subsequent job or JS7 - If Instruction.
    • If the job configuration specifies one or more Return Codes on Warning and if the job's return code matches one of the values then a notification is created. Otherwise the job will terminate successfully without a warning.
  • For details see JS7 - Job API.

If a warning is created then the Monitor->Order Notifications view will display the warning for a job like this:

Image Added


Optionally notifications for warnings are sent by mail if configured by JS7 - Notification.

Terminating Job with error

The typical error handling for JavaScript applies:

  • If an exception is raised then this will cause the job to terminate immediately with error. This applies to unsolicited errors and to exceptions raised by a throw statement.
  • Users are encouraged to apply try .. catch .. finally statements for better control of error handling.


Code Block
languagejs
titleExample for implementation of JS7Job with JavaScript
linenumberstrue
class JS7Job extends js7.Job {

	processOrder(js7Step) {
        try {
            js7Step.getLogger().info( '.. try: do some stuff')
			throw 'error occurred, exiting job';
        } catch (e) {
          	js7Step.getLogger().info('.. catch: do some error handling')
            throw e;
        } finally {
          	js7Step.getLogger().info('.. finally: do some cleanup such as closing database connections')          
        }
    }
}