Sleep function in server side script?

ishtein
Mega Contributor

In my server side script, I am triggering an action via an outbound ReST call. The asynchronous operation returns immediately, but provides a URL which I can poll for the operation's completion. I would like to keep the function atomic, so would like to poll the URL, and if the operation hasn't yet completed, would like to wait for a second or so and poll again, and do that for several times (I do not expect the operation to take more than 10-20 seconds, normally not more than 5 seconds) until done.

I am looking for something like setTimeout or setInterval function that I could use on the server, so that I can tell my script to wait, but can't find anything. Am I missing something? Can somebody point me to a solution for this kind of problem?

I have seen a timer activity in Workflow, which would pause the workflow for a specified period of time; it can probably serve as a workaround, but I wanted a programmatic (and programmable) solution. Will be grateful for any guidance!

17 REPLIES 17

Chuck Tomasi
Tera Patron

Have you taken a look at gs.sleep(milliseconds)?



http://wiki.servicenow.com/index.php?title=GlideElement#gsc.tab=0



I should also mention that it's only available to global apps (not scoped.)


Yes, I saw that function, and also saw that it's only available to global apps. I have a scoped application, so am not able to use gs.sleep() :-(.


You might find this thread helpful.



gs.sleep() in scoped application?


I like the idea of using callbacks, but how do I do that in my situation? I am invoking a third party operation, they provide URL for polling. The only API I can use is ReST. How can I solve my conundrum?