Forum Discussion

MuraliNagula's avatar
MuraliNagula
New Contributor
7 years ago

How to replicate the logic equivalent to while loop in Snaplogic pipelines

There is a child pipeline which returns values like completed, in queue, processing etc. The requirement is that parent pipeline to run this child pipeline till it returns Completed, of-course after certain wait time. Its like while loop, run the child pipeline, till the expression is true. How do accomplish this in snaplogic ?

Appreciate any pointers…

14 Replies

  • christwr's avatar
    christwr
    Contributor III

    I’ve seen people suggest creating a Triggered Task for the child pipeline, and then have the parent pipeline call the child pipeline via REST GET snap and use the REST GET snap’s “Has Next” and “Next URL” capabilities (typically for paging) to do a while loop. The child pipeline has to return something that the parent “Has Next” can evaluate.

    • MuraliNagula's avatar
      MuraliNagula
      New Contributor

      How and where do set these “Has Next” and “Next URL” in the triggered task ?

  • tstack's avatar
    tstack
    Former Employee

    Can you explain what processing you’re doing? Maybe focus less on the mechanics so that we can understand the use case.

    • MuraliNagula's avatar
      MuraliNagula
      New Contributor

      The parent pipeline queues up a bulk job to export records. The child pipeline keeps getting the status of the job every 60 seconds to get the status till it reaches its end state. I have tried to put everything in the parent pipeline but looks like child pipeline is the best way to go.

  • psadasivam's avatar
    psadasivam
    New Contributor III

    @MuraliNagula - This can be achieved using "Has next "and “Next URL” properties. Below rest snap invokes Next URL based on Has next flag. You can refer Snap documentation for more info.

    • tstack's avatar
      tstack
      Former Employee

      I just wanted to add on that you should set the ‘Pagination interval’ as well so that the requests aren’t made too quickly.

  • Unfortunately the response object for this Marketo Endpoint doesn’t have “Has Next” or “Next URL” attributes. Otheriwse my life would have been much easier !!!

    You can find the details of the response object etc in the following link.

    https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Bulk_Export_Leads/getExportLeadsStatusUsingGET

    GET /bulk/v1/leads/export/{exportId}/status.json

    https://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Bulk_Export_Leads/getExportLeadsStatusUsingGET

    • tstack's avatar
      tstack
      Former Employee

      The “next” properties are expressions. So, I would think you could write an expression to check the response to the status request to see if it was completed or not. If it was completed, the ‘Has Next’ expression should return false, otherwise it should return true. The ‘Next URL’ can just be the same as the main Service URL property.

  • cstewart's avatar
    cstewart
    Former Employee

    In the documentation for the REST Get Snap, there is an example for response form marketo:
    REST Get Pagination: Marketo
    For Marketo, set:

    Has Next: resultdoc.moreResult
    Next URL: “/rest/v1/activities.json?nextPageToken=” + resultdoc.nextPageToken + ”&activityTypeIds=1&activityTypeIds=12”

  • christwr's avatar
    christwr
    Contributor III

    The API for the child triggered task doesn’t have to return “Has Next” or “Next URL” properties directly, just something you can evaluate in expressions for those attributes in the REST GET snap.

    For example:

    Or whatever type of expression that returns true/false based on whether you want the REST GET snap to do again…