Random time delay

Sometimes a random delay is needed to prevent the execution of parallel workflows like project creation, if that one is triggered by a watchfolder with identical prefix names.

An easy solution for this is by using the Javascript Action Node:

// Function to generate a random integer between min (inclusive) and max (inclusive)
function getRandomDelay(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Define the minimum and maximum delay in milliseconds
var minDelay = 10;
var maxDelay = 6000;

// Get the random delay
var randomDelay = getRandomDelay(minDelay, maxDelay);

// Convert delay to milliseconds
var delayInMilliseconds = randomDelay;

// Pause execution for the random delay
java.lang.Thread.sleep(delayInMilliseconds);

// Return the delay to indicate completion / debug information
randomDelay;

Last updated