Stephen Gilmore

Workday Studio "exit()"


#Workday #Workday Studio #TIL

Today I learned there is an MVEL expression do do a "System.exit" or "sys.exit()" in Workday Studio.

context.setAbort(true)

Important: The default behavior of all local-out steps is Propogate Abort = true. Generally you'll want this. If the abort isn't working as expected, check that setting first.

Example

1. Set an integration time limit

Somewhere near the beginning of the integration, set a time limit on the integration.

// You could simply set a global value
props["runtimeLimitHours"] = 3.9

// OR you could retrieve it from a launch parameter or integration attribute
props["runtimeLimitHours"] = Double.valueOf(lp.getSimpleData("Runtime Limit (hours)"));

If you use a launch parameter or integration attribute, consider adding an ValidateExp that the value is between 0 and 4 hours

2: Evaluate the run duration

So for example, say you're in a loop processing a few thousand records. After the splitter, you might have an eval component with something like this:

// 1. Get the current time and the 'sent' time in milliseconds
long nowMs = System.currentTimeMillis();
long sentMs = lp.sentOnAsDate.getTime();

// 2. Calculate the difference in milliseconds
long diffMs = nowMs - sentMs;

// 3. Convert to hours as a double (to support decimals like 3.75)
// There are 3,600,000 milliseconds in one hour
double diffHours = diffMs / 3600000.0;

// 4. Logic check
if (diffHours > props["runtimeLimitHours"]) {
    // Logic for when the time limit is exceeded
    props["abortIntegration"] = true;
} else {
    props["abortIntegration"] = false;
}

3. Route by duration

Then you could have a route step that checks props["abortIntegration"] for each record. The choose-route expression would be something like:

// abort
(boolean)props["abortIntegration"] == true

// continue
(boolean)props["abortIntegration"] == false

4. Handle the abort

The last thing in the logic path will be an eval step with context.setAbort(true). Do any steps to close out the integration before the context.setAbort. So for example, there might be steps like:

  1. Log a CRTICICAL message in a PutIntegrationMessage step
  2. Close/save any log files with a local-out step
  3. eval step to trigger the abort with context.setAbort(true)