Fail-Retry
DESCRIPTION: This flow allows the user to check the nodes or operations for failures and then retry for chosen amount of times. The user can choose the key to check for and also choose if flow should check for failures or a success. Once a message comes without a failure indicator(or with a success indicator) within retries, the message is passed to another node or operation. If such case can not be reached the flow returns an error and the message can not be passed to other operations. With these specifications, this flow can be used to create Back-End To-Do Lists (Schedules). These To-Do Lists will not be occupied by the messages that have failed at the very first steps. And also the user will be able to see if some of their operations have some problems to fix and which one.
DETAILS:
This flow takes 4 Inputs: Condition, Number of Retries, Variable to Check, Condition Type. (A descriptive image will be given)
Condition is the input where the user sets the fail/success indicator.
Number of Retries is the input where the user sets the retry number of the flow.
Variable to Check is the input where the user sets the message object's key that holds the condition.
Condition Type is the input where the user sets if the flow should take the condition as a fail or success, with this option condition can be a success or a fail indicator.
Here are the input variables:
IMPORTANT NOTE: This flow uses msg.checkOne, msg.checkTwo, msg.checkThree, msg.checkFour keys to function. If a message has any of those keys the message can be damaged.
OUTPUTS:
- First output should be attached to the beginning of the operation since it is the retry output.
- Second output is the success output, it should be attached to the next operation.
- Third output is the fail output, it can be used for debugging.
[{"id":"302b0e8245331265","type":"subflow","name":"Fail-Retry","info":"","category":"","in":[{"x":80,"y":240,"wires":[{"id":"c6e190a1b64cd1e9"}]}],"out":[{"x":980,"y":140,"wires":[{"id":"07e230f5e83ffa2b","port":0},{"id":"aecd479a77e1c9f6","port":0}]},{"x":980,"y":240,"wires":[{"id":"07e230f5e83ffa2b","port":1},{"id":"aecd479a77e1c9f6","port":1}]},{"x":980,"y":340,"wires":[{"id":"07e230f5e83ffa2b","port":2},{"id":"aecd479a77e1c9f6","port":2}]}],"env":[{"name":"Condition","type":"num","value":"403","ui":{"icon":"font-awesome/fa-sort-numeric-asc"}},{"name":"Number of Retries","type":"num","value":"10","ui":{"icon":"font-awesome/fa-exclamation"}},{"name":"Variable to Check","type":"str","value":"statusCode"},{"name":"Condition Type","type":"str","value":"Fail","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"Fail"},"v":"Fail"},{"l":{"en-US":"Success"},"v":"Success"}]}}}],"meta":{},"color":"#3FADB5","icon":"node-red/sort.svg"},{"id":"07e230f5e83ffa2b","type":"function","z":"302b0e8245331265","name":"","func":"\nlet msg1; // Output 1 -> Fail but keep trying\nlet msg2; // Output 2 -> Success\nlet msg3; // Output 3 -> Failed too much, error output. (System Stops)\n\nif(msg.checkOne !== msg[msg.checkThree] && msg.failCounter !== msg.checkTwo){\n msg.failCounter = msg.failCounter + 1;\n msg1 = msg;\n} else if(msg.checkOne === msg[msg.checkThree]){\n msg.failCounter = 0;\n msg2 = msg;\n} else {\n msg.payload = \"Too much error!!\"\n msg3 = msg;\n}\n\n\nreturn [msg1, msg2, msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":420,"wires":[[],[],[]]},{"id":"c6e190a1b64cd1e9","type":"change","z":"302b0e8245331265","name":"","rules":[{"t":"set","p":"checkOne","pt":"msg","to":"Condition","tot":"env"},{"t":"set","p":"checkTwo","pt":"msg","to":"Number of Retries","tot":"env"},{"t":"set","p":"checkThree","pt":"msg","to":"Variable to Check","tot":"env"},{"t":"set","p":"checkFour","pt":"msg","to":"Condition Type","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":240,"wires":[["0988cb07d7d07051"]]},{"id":"aecd479a77e1c9f6","type":"function","z":"302b0e8245331265","name":"","func":"\nlet msg1; // Output 1 -> Fail but keep trying\nlet msg2; // Output 2 -> Success\nlet msg3; // Output 3 -> Failed too much, error output. (System Stops)\n\nif(msg.checkOne === msg[msg.checkThree] && msg.failCounter !== msg.checkTwo){\n msg.failCounter = msg.failCounter + 1;\n msg1 = msg;\n} else if(msg.checkOne !== msg[msg.checkThree]){\n msg.failCounter = 0;\n msg2 = msg;\n} else {\n msg.payload = \"Too much error!!\"\n msg3 = msg;\n}\n\n\nreturn [msg1, msg2, msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":60,"wires":[[],[],[]]},{"id":"0988cb07d7d07051","type":"function","z":"302b0e8245331265","name":"","func":"\nlet msg1;\nlet msg2;\n\nif(msg.checkFour === \"Fail\"){\n msg1 = msg;\n} else if(msg.checkFour === \"Success\") {\n msg2 = msg;\n}\n\nreturn [msg1, msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":240,"wires":[["aecd479a77e1c9f6"],["07e230f5e83ffa2b"]]}]