This repository was archived by the owner on Nov 9, 2022. It is now read-only.
Repository navigation
Condition Modules
Anthony Clavio edited this page Nov 24, 2020
·
4 revisions
Condition modules are a unique feature of the MarkLogic State Conductor. Condition modules are referenced by a Choice states' choice rules "Resource" field. Custom condition modules can be written in server-side javascript and referenced in your State Machine definition files.
Condition modules are responsible for determining if a branch of a Choice state should be taken.
Custom condition modules must export a function named checkCondition with the following signature:
'use strict';
function checkCondition(uri, options = {}, context = {}) {
// TODO return boolean
return true;
}
exports.checkCondition = checkCondition;- uri - (String) the URI of the in-process document
- options - (Object) a JSON object containing values from the "Parameters" field of the current Task state
- context - (Object) the JSON context object of the current Execution. Used to pass data between state-machine states.
- return - (Boolean) the value returned by the
checkConditionfunction must be truthy or falsey, and represents if the associated branch should be taken.- If the return value is
truethe state machine will transition to the state named in the "Next". - If the return value is
falsethe next choice rule of the current state will be evaluated.
- If the return value is
Custom condition modules should be deployed alongside any application code to your application's Modules database. They are then referenced by URI relative to the root of that Modules database.
example:
{
"Type": "Choice",
"Comment": "example choice state",
"Choices": [
{
"Resource": "/my-application/conditions/option1.sjs",
"Comment": "checks for option1 condition",
"Parameters": {
"param1": "hello",
"param1": "world"
},
"Next": "performOption1"
},
{
"Resource": "/my-application/conditions/option2.sjs",
"Comment": "checks for option2 condition",
"Parameters": {
"paramName": "test"
},
"Next": "performOption2"
},
{
"Resource": "/my-application/conditions/option3.sjs",
"Comment": "checks for option3 condition",
"Next": "performOption3"
}
],
"Default": "FallbackState"
}