Last active
November 15, 2018 19:42
-
-
Save ej-github/770222a517c074a43f31203fbf8cb723 to your computer and use it in GitHub Desktop.
Check if a vRO workflow has running/waiting executions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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