Polling an external url

Hi, I’m trying to implement a tool that will allow me to generate and import data from an external service. However, the request to generate the data requires polling an endpoint for the data to become available. (Think a reporting tool, submit the request, wait for the report to generate).

I’m trying to figure out how to repeatedly poll for the response. I tried setting up a recursive procedure that would request the data via “tm-http-request” and repeat the request if the data wasn’t found in the oncompletion procedure, but I wasn’t seeing any sign of the recursion.

My example code. If the url is complete, it loads the data fine. But if finished == 0, it seems to just die rather than calling request_update again.

\procedure get-status()
<$list filter="[<data>jsonget[finished]compare:number:eq[1]">
<$action-createtiddler
    $overwrite="yes"
    $basetitle="Test Response"
    text={{{ [<data>jsonget[text]] }}}
    status=<<status>>
/>
</$list>
<$list filter="[<data>jsonget[finished]compare:number:ne[1]">
<<request-update>>
</$list>
\end get-status
\procedure request-update()
<$action-sendmessage
    $message="tm-http-request"
    url={{response_url}}
    oncompletion=<<get-status>>
/>
</$set>
\end request-update


<$button>Request
<<request-update>>
</$button>

Anyone have a good suggestion, or experience/examples with polling potentially long running httprequests in the background?

Welcome to the forum!

What does <data> resolve to?

get-status is invoked in a new context in terms of variables and is not aware of request-update. You can make request-update global, or pass the variable to get-status:

<$action-sendmessage
    $message="tm-http-request"
    url={{response_url}}
    oncompletion=<<get-status>>
    var-request-update=<<request-update>>
/>