Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Link Call node #3152

Merged
merged 6 commits into from
Oct 1, 2021
Merged

Add Link Call node #3152

merged 6 commits into from
Oct 1, 2021

Conversation

knolleary
Copy link
Member

@knolleary knolleary commented Sep 29, 2021

  • New feature (non-breaking change which adds functionality)

Proposed changes

Adds a new 'link call' node that can be used to 'call' a link-in node and get a response.

To support this behaviour, the link-out node has an option to 'return to sender'. When in that mode, if cannot be wired to link-in nodes and will send any messages it receives that originated from a link-call node, back to the calling node.

There are some specific restrictions in behaviour:

  1. a link-call node can only send to one link-in node. It cannot be used to trigger multiple flows and somehow combine the results. (That could be considered in the future)
  2. the link-call node can be configured with a timeout, default 30 seconds. If a response is not received in that time, it will call node.error() and trigger any Catch nodes in scope. Note that if the called flow then does response after the timeout, its response will be sent on as normal, but the complete node will not get triggered.
  3. the called flow must return a message via a link-out node.
    • if the single message passed to the link-call node results in multiple messages being passed to the link-return (such as a Split node inside the called flow), then the Complete node will be triggered after the first of the return messages is received. Similarly, the timeout handling will be cleared when that first message comes back.

@coveralls
Copy link

coveralls commented Sep 29, 2021

Coverage Status

Coverage increased (+0.07%) to 67.745% when pulling f1cbca8 on link-call into 36bb172 on dev.

@knolleary
Copy link
Member Author

Decided to add timeout option to the link-call node for the initial version as it makes cleaning up internal state easier for calls that never return.

@knolleary
Copy link
Member Author

Help text updated. Now ready to merge.

@knolleary knolleary marked this pull request as ready for review September 29, 2021 13:46
@dceejay
Copy link
Member

dceejay commented Sep 30, 2021

looks good to start. Mentally I think of calling down to a subroutine and tend to lay out flows with link function further down the page so the icon seems at odds to me - but functionally works fine. Happy to merge

image

@knolleary knolleary merged commit da114fa into dev Oct 1, 2021
@Steve-Mcl
Copy link
Contributor

Great to see this merged.

Had a bit play & did a recursive string reverse

ewO4jdRFCd

[{"id":"346af0519ba4be19","type":"link in","z":"b872cb4b.5a6448","name":"string reverse","links":[],"x":430,"y":420,"wires":[["bd8f78bd4dd96f52"]],"l":true},{"id":"65131b465df6cf7d","type":"inject","z":"b872cb4b.5a6448","name":"olleH","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"olleH","payloadType":"str","x":410,"y":320,"wires":[["20a876e9039cbf4a"]]},{"id":"bd8f78bd4dd96f52","type":"switch","z":"b872cb4b.5a6448","name":"length == 1","property":"payload.length","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":420,"wires":[["43ef4c342967de07"],["d06dd3480408574d"]]},{"id":"1aa2b1be9675d866","type":"link out","z":"b872cb4b.5a6448","name":"","mode":"return","links":[],"x":1675,"y":440,"wires":[]},{"id":"8ee4e912a201841f","type":"link call","z":"b872cb4b.5a6448","name":"","links":["346af0519ba4be19"],"timeout":"30","x":1200,"y":440,"wires":[["231862c8feba4aa3"]]},{"id":"261e9bc5cd4ec0b8","type":"change","z":"b872cb4b.5a6448","name":"slice 1 off end","rules":[{"t":"set","p":"payload","pt":"msg","to":"$substring(payload, 0, ($length(payload) - 1))\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":440,"wires":[["8ee4e912a201841f"]]},{"id":"20a876e9039cbf4a","type":"link call","z":"b872cb4b.5a6448","name":"","links":["346af0519ba4be19"],"timeout":"30","x":580,"y":340,"wires":[["82359688f01ff310"]]},{"id":"82359688f01ff310","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":340,"wires":[]},{"id":"231862c8feba4aa3","type":"change","z":"b872cb4b.5a6448","name":"append","rules":[{"t":"set","p":"payload","pt":"msg","to":"/*  $substring(a[$count(a)-1], $length(a[$count(a)-1])-1, 1) & payload */\t\t/* $substring(payloadBefore, $length(payloadBefore)-1, 1) & payload */\t/* $substring(a[$count(a)-1], $length(a[$count(a)-1])-1, 1) & payload*/\tlastcharArray[$count(lastcharArray)-1] & payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1380,"y":440,"wires":[["fa34b41b05dcaee0"]]},{"id":"fa34b41b05dcaee0","type":"function","z":"b872cb4b.5a6448","name":"pop last char","func":"msg.lastcharArray && msg.lastcharArray.pop()\nreturn msg\n\n ","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":440,"wires":[["1aa2b1be9675d866"]],"icon":"font-awesome/fa-copy"},{"id":"d06dd3480408574d","type":"function","z":"b872cb4b.5a6448","name":"Push last char","func":"\nmsg.lastcharArray = msg.lastcharArray || []\nmsg.lastcharArray.push(msg.payload.substr(-1))\nreturn msg\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":440,"wires":[["261e9bc5cd4ec0b8"]],"icon":"font-awesome/fa-copy"},{"id":"43ef4c342967de07","type":"link out","z":"b872cb4b.5a6448","name":"","mode":"return","links":[],"x":735,"y":400,"wires":[]},{"id":"38408f72199ae701","type":"inject","z":"b872cb4b.5a6448","name":"eybdooG","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"eybdooG","payloadType":"str","x":400,"y":360,"wires":[["20a876e9039cbf4a"]]}]

Obviously it is of little use other than to demonstrate recursion is possible :)

@knolleary knolleary deleted the link-call branch October 3, 2021 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants