Planning Analytics

 View Only
Expand all | Collapse all

ExecuteWithReturn asynchronously?

  • 1.  ExecuteWithReturn asynchronously?

    Posted Mon February 01, 2021 10:37 AM
    I'm using the REST API to execute a process, and I'm having trouble when the process takes a long time (over a minute or two) to return. If the process is quick, I get a response status of "CompletedSuccessfully". If the process takes too long, I get a 502 error back from the server. In an ideal world, I'd like to kick off a process and then have a mechanism to poll the server and get the result when the process finishes. Is that possible?

    ------------------------------
    Rob Gordy
    ------------------------------

    #PlanningAnalyticswithWatson


  • 2.  RE: ExecuteWithReturn asynchronously?

    Posted Mon February 01, 2021 12:51 PM
    Yes, you'll want to look at the async specifications from odata. If you're using tn1py you can enable cloud mode and it will handle it for you. 

    Sent from my mobile phone





  • 3.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 02, 2021 07:12 AM
    Hi Rob,

    I believe this is the ODATA documentation you're looking for: http://docs.oasis-open.org/odata/odata/v4.0/os/part1-protocol/odata-v4.0-os-part1-protocol.html#_Toc372793632

    respond-async is a header


    ------------------------------
    Stuart King
    IBM Planning Analytics Offering Manager
    ------------------------------



  • 4.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 02, 2021 04:41 PM
    Edited by System Test Fri January 20, 2023 04:33 PM
    Stuart and Ryan,
    Thank you for the pointers to the OData documentation. I believe I understand it all and added the respond-async header to my calls. It's providing a "Location" header in the 202 response, but I'm having difficulty interpreting it. The header is: 
    location: "../_async('BAUKBBAAZzgCWcmZG7ERRgwV3jNy7A')",
    What would my GET URL look like? I tried the following, but I got a 404 error.
    I feel like I'm close to getting this resolved, so any help would be appreciated.
    Regards,
    Rob

    #PlanningAnalyticswithWatson


  • 5.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 02, 2021 05:00 PM
    Edited by System Test Fri January 20, 2023 04:11 PM
    Stuart and Ryan,
    I had a typo in my GET URL. I'm getting a response w/the GET call to the Location URL, but it's a 404 (Resource Not Found) response. The body says:
    { "error": { "code": "278", "message": "Resource '/api/v1/_async('DQ3KBBAALDEiJxFi6Zt-cG044TciLA')' not found" } }
    Again, any help would be appreciated.

    Regards,
    Rob

                                                                                                                              

    Robert W. Gordy 

    Chief Technology Officer
    Revelwood Inc. 

    201-984-3021 direct

    rgordy@revelwood.com


    #PlanningAnalyticswithWatson


  • 6.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 02, 2021 05:12 PM

    Hey Rob,

    You are getting close. You can see a working example in TM1Py here( https://github.com/cubewise-code/tm1py/blob/e518e14147ce22c6f3eab0dd09cc0245a696f883/TM1py/Services/RestService.py#L64)

     

    In this wrapper function you can see that after the request is issued the RESTService queries the async object every x seconds. When it returns a 200 or 201 (it can only do this one time, then the async object is deleted). You can process the contents of that response like this https://github.com/cubewise-code/tm1py/blob/e518e14147ce22c6f3eab0dd09cc0245a696f883/TM1py/Services/RestService.py#L508

     

    Thanks

    Ryan

     

     






  • 7.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 02, 2021 05:53 PM
    Ryan,

    I reviewed the Python code and saw how they handle the Async calls. My plan is to modify my code to do something very similar. In the meantime, I was using Postman to test this out, and that's where I was getting the 404 error. I'm going to give up on this for the day and hope that I'll get over the finish line tomorrow. I'll keep you posted. 

    Thanks again for your assistance.

    Rob

    ------------------------------
    Robert Gordy
    ------------------------------



  • 8.  RE: ExecuteWithReturn asynchronously?

    Posted Wed February 03, 2021 03:55 AM
    Hi Rob,

    You might be interested to know that TM1, as of version 11.8.0, has implemented support for the newer OData v4.01 async response format as mentioned here: https://docs.oasis-open.org/odata/new-in-odata/v4.01/cn04/new-in-odata-v4.01-cn04.html#_Toc21700018.

    The updated, v4.01, specification for Asynchronous Requests can be found here: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31359016.

    Long story short: whereas today you'll have to allow application/http as an acceptable content-type, denying application/http explicitly, while allowing the type returned by the request presumably (typically application/json, although I don't think we explicitly verify that), you will get this new style response in which makes processing it, other than having to look at the AsyncResult header, the same as processing the response as if they request had not been executed asynchronously.

    ------------------------------
    Hubert Heijkers
    ------------------------------



  • 9.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 09, 2021 10:29 AM
    Stuart, Ryan, and Hubert,

    I just want to say thanks for your help here. Nina and I were able to get everything working properly, and we learnt a lot along the way! 

    One last question: does PA do anything with "wait" parameter in "Prefer: respond-async, wait=10"? From what we can tell, we immediately get back a 202 response which tells us to start our polling. I thought the "wait" parameter would allow us to tell the server we'll wait for a proper (i.e. 200) response for 10 seconds, but if it'll be longer, we'd rather get the 202. Do I have that right?

    Regards,
    Rob

    ------------------------------
    Robert Gordy
    ------------------------------



  • 10.  RE: ExecuteWithReturn asynchronously?

    Posted Tue February 09, 2021 02:29 PM
    Hi Rob,

    You concluded correctly, support for the wait parameter, apart from respond-async being a preference (and preference can be ignored by a service;-), has not been implemented by TM1 server as you know it. Plans are we'll add support for it in the next major TM1 server version ;-)

    Cheers,

    -H

    ------------------------------
    Hubert Heijkers
    ------------------------------



  • 11.  RE: ExecuteWithReturn asynchronously?

    Posted Wed February 10, 2021 08:07 PM
    Hi Rob:

    The IBM docs here in "Supported preferences" list the Prefer values that are supported by the TM1 REST API. Respond-async (ODATA 8.2.8.8) is listed, but wait (ODATA 8.2.8.9) is not. Maybe support for that will get ​added at some point, but for now it's safe to say you aren't missing something-- wait is just being ignored by the TM1 REST API/Server.

    Regards,
    Mike

    ------------------------------
    Michael Cowie
    QueBIT Consulting
    Tuscaloosa AL
    ------------------------------