How to Delay a Process Execution Using Groovy

Document created by Adam Arrowsmith Employee on Feb 16, 2012Last modified by Adam Arrowsmith Employee on Mar 9, 2016
Version 3Show Document
  • View in full screen mode
The article describes how to introduce a delay into a process execution by using a Groovy scripting step.

Use Case

You want to temporarily delay or pause a Process execution from continuing for some amount of time to allow an external application to perform some operations.
For example, you have a process that fails when attempting to connect and send data to a specific source. Try/Catch logic can retry, but it may occur too quickly and the destination you're connecting to doesn't have enough time to free up necessary resources to allow the connection.


The solution is to use a Data Process Custom Scripting step to effectively pause the process execution for a configurable amount of time before continuing.

Add a Data Process shape with a Custom Scripting step configured with the script below to the process at the point where you want to pause the execution. Modify the waitFor variable at the beginning of the script to the desired length of time to wait in seconds.


// Specify the length of time to wait in seconds.
int waitFor = 30;

Thread.sleep(waitFor * 1000);

// Leave the rest of the script as-is to pass the Documents to the next step.
for ( int i = 0; i < dataContext.getDataCount(); i++ ) {
    InputStream is = dataContext.getStream(i);
    Properties props = dataContext.getProperties(i);

    dataContext.storeStream(is, props);



The example processes below achieve the following:

  • Should a connection fail, it will automatically retry based on the Try/Catch settings.
  • Delay the connector from firing for X seconds.
  • Should the process fail after the maximum number of Try/Catch retry attempts, it fails with an exception.

** Note: Not all shapes are completely configured in this example, as this should be used for guidance and not for direct copy/paste-style use.


Example 1: Only delay for retry calls

Execute first connector call immediately without delay but then introduce a delay before retrying.




Example 2: Delay before every call

Delay before every connector call including the first attempt.




Usage Considerations

The primary difference between these examples is having the initial Try/Catch (or not), and the retry count. Both processes will execute the NetSuite connector at most five times per the following brief overview of steps:
Option 1:Process Start > NetSuite > Delay > NetSuite > Delay NetSuite > Delay NetSuite > Delay > NetSuite > Exception.
Option 2: Process Start > Delay > NetSuite > Delay NetSuite > Delay NetSuite > Delay > NetSuite > Delay > NetSuite > Exception.
** Option 2 is hitting the delay one more time than option 1, in theory, making it 30 seconds longer, due to the scripting configuration of 30 seconds as shown in the code snippet above.

14 people found this helpful