Skip to content

Instantly share code, notes, and snippets.

@ej-github
Last active November 15, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ej-github/770222a517c074a43f31203fbf8cb723 to your computer and use it in GitHub Desktop.
Save ej-github/770222a517c074a43f31203fbf8cb723 to your computer and use it in GitHub Desktop.
Check if a vRO workflow has running/waiting executions
// Check if a vRO workflow has running/waiting executions
//
// For vRO 7.0+
//
// Action Inputs:
// targetWorkflow - Workflow - Workflow to check running status
//
// Return type: boolean
var lockName = "RunningWorkfowCheck";
var lockId = "vco";
try {
System.log("Lock and check if workflow '"+targetWorkflow.name+"' is running...");
LockingSystem.lockAndWait(lockName, lockId);
var wfTokens = targetWorkflow.executions;
var runningCount = 0;
for each (var wfToken in wfTokens) {
var state = wfToken.state.toLowerCase();
if ((state != "running") && (state != "completed") && (state != "failed") && (state != "waiting") && (state != "canceled")) {
System.error("Unknown workflow state '" + wfToken.state + "'");
}
if ((state == "running") || (state == "waiting")) {
runningCount++;
if (runningCount > 1) {
System.log("Workflow '"+targetWorkflow.name+"' is already running.");
return true;
}
}
}
System.log("No running workflow executions found for '"+targetWorkflow.name+"'.");
} catch (e) {
System.log("Unlock workflow running check.");
LockingSystem.unlock(lockName, lockId);
throw e;
} finally {
System.log("Unlock workflow running check.");
LockingSystem.unlock(lockName, lockId);
}
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment