Scheduled Script Handling of Server Restarts

Sometimes, a scheduled script might fail if the application server restarts, for example, for a NetSuite update, maintenance, or an unexpected issue. Restarts can force a script to stop anytime, so your scripts should handle restarts and recover from interruptions.

In SuiteScript 2.x, if a failure happens, the script restarts from the beginning. NetSuite knows when a scheduled script was stopped and restarts it as soon as the needed resources are ready. You don't manually script yields or recovery points in SuiteScript 2.x, so it's easier to manage restarts.

In your scheduled script, check the context.type attribute to see if the script was restarted (if context.type === "aborted"). For example:

          /**
 * @NApiVersion 2.x
 * @NScriptType ScheduledScript
 */
define([], function(){
    return {
        execute: function (context)
        {
            if (context.type === 'aborted')
            {
                // I might do something differently
            }
            .
            .
            .
        }
    }
}); 

        

Want more details about the context argument? See context.InvocationType.

The following example scripts demonstrate how restarts impact scheduled script execution:

Related Topics

General Notices