Forum Discussion

masterkrause's avatar
masterkrause
New Contributor
6 years ago

Recursive Pipeline Solution

I am curious about using recursive pipelines. I know the documentation says that we should not use pipelines in a recursive manner but for some solutions, I think it makes sense. I have created two pipelines: Recursion Parent and Recursion Child.The Recursion Parent passes in a simple js variable, $test which is set to 2 in this case. The Recursion Parent then calls the Recursion Child pipeline which then increments $test by 1 while subsequently decrementing the pipeline parameter param by 1. Once param == 0 then the Child pipeline stops and returns the value of $test and a status, in this case “completed”.

Recursive Parent Input

Recursive Parent Output

Recursive Child Input

Recursive Child Pipeline Execute

My question/point to this is: Why is recursion not supported? It obviously works with a minor work around.

7 Replies

  • tstack's avatar
    tstack
    Former Employee

    Recursion is not supported because it’s too easy to lose control of the execution and have it start spawning child executions and overloading the Snaplex.

    Can I ask what you’re trying to achieve?

    • masterkrause's avatar
      masterkrause
      New Contributor

      My team wants to be able to get a list of pipelines that call other pipelines. For example:

      Pipeline A calls Pipeline B. Pipeline B calls Pipeline C.

      Using recursion is the most elegant, and in my opinion, the most correct way to traverse this type of list. Furthermore, we know that there is a limit to how many children can be called, for us it is about 50. For traversing pipelines, we will never have more than 4 or 5 nested children at a time.

  • christwr's avatar
    christwr
    Contributor III

    Isn’t recursion where something calls itself?

    You should be able to have A that calls B, and then B that calls C.

    Sounds like maybe you’re just trying to implement looping (until param == 0)?

    • christwr's avatar
      christwr
      Contributor III

      Not sure if it’s “legit” from SnapLogic’s perspective, but you can implement looping between parent/child pipelines. Have the child pipeline exposed via triggered task, then have parent pipeline use REST GET snap to call the child pipeline triggered task, and use the REST GET’s pagination features (Has Next & Next URL) to evaluate some criteria and re-GET the child pipeline until criteria is false.

  • normpw's avatar
    normpw
    New Contributor

    Thanks christwr your looping solution helped me to loop through an REST Post until successfully getting success from a sha356 hash password.

    • RogerSramkoski's avatar
      RogerSramkoski
      Employee

      Hello normpw, thank you for joining our Community and making your first post one that shares your success from christwr’s suggestion!