BasicCalculator
{
"Comment": "Simple Calculator Step Functions Example",
"StartAt": "state.start.operatorSelector",
"States": {
"state.start.operatorSelector": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.operator",
"StringEquals": "add",
"Next": "state.process.operator.add"
},
{
"Variable": "$.operator",
"StringEquals": "subtract",
"Next": "state.process.operator.subtract"
},
{
"Variable": "$.operator",
"StringEquals": "multiply",
"Next": "state.process.operator.multiply"
},
{
"Variable": "$.operator",
"StringEquals": "divide",
"Next": "state.process.operator.divide"
}
],
"Default": "state.process.operator.unknown"
},
"state.process.operator.add": {
"Type": "Pass",
"Comment": "Performs an addition on the operands provided",
"Next": "state.process.displayResult"
},
"state.process.operator.subtract": {
"Type": "Pass",
"Comment": "Performs an subtraction on the operands provided",
"Next": "state.process.displayResult"
},
"state.process.operator.multiply": {
"Type": "Pass",
"Comment": "Performs an multiplication on the operands provided",
"Next": "state.process.displayResult"
},
"state.process.operator.divide": {
"Type": "Pass",
"Comment": "Performs an division on the operands provided",
"Next": "state.process.displayResult"
},
"state.process.operator.unknown": {
"Type": "Fail",
"Error": "UNKNOWN_OPERATOR",
"Cause" : "The operator provided is not supported"
},
"state.process.displayResult": {
"Type": "Pass",
"Next": "state.process.complete"
},
"state.process.complete": {
"Type": "Pass",
"End": true
}
}
}
Hãy dành một chút thời gian để xem lại định nghĩa state machine và biểu diễn đồ họa. Workflow hiện tại đưa ra quyết định dựa trên dữ liệu đầu vào, nhưng không thực hiện bất kỳ tính toán nào - tất cả các trạng thái đều là “Pass” hay còn gọi là no-op trong thuật ngữ State Language.
{
"operator" : "add",
"operands" : [
1,
2
]
}