Retry REST Message in case of failure for GET call (outbound)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2022 02:25 AM - edited 12-02-2022 10:36 AM
using below code I am triggering a REST message through Scheduled job, I want to retry the same REST call if that if the response is other than 200, I want to do it retry 5 times or till the time I get 200(whichever is earlier) wit the interval of 10 seconds, ifretry is successful then break the retry and come out the if/while an run next line of code, I am not sure whatever I have written is correct, please advise.
var retrycount = 0 ;
var r = new sn_ws.RESTMessageV2(REST message, REST Method));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
while(httpStatus != '200' && retrycount < gs.getProperty('integration.retry_count')){ // property to store max retries
retrycount++;
gs.sleep(gs.getProperty('integration.retry_interval')); .// property that has interval time defined in MS
var response = r.execute();
if(httpStatus == '200'){
break;
}
}
@Ankur Bawiskar @Maik Skoddow @Mike_R @Saurav11 @Gunjan Kiratkar @AnubhavRitolia @Mohith Devatte @Murthy Ch @Chuck Tomasi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2022 11:21 AM
Try it and see if it works.
one thing i can point out is that you don't need to declare your variables again in the while loop.
For example, in the while loop, instead of
var response = r.execute();
you can just do
response = r.execute();