Skip to content

Instantly share code, notes, and snippets.

@a-chumagin
Created June 20, 2018 12:20
Show Gist options
  • Save a-chumagin/76b774b0d96669a02c5d07fdc07c83e6 to your computer and use it in GitHub Desktop.
Save a-chumagin/76b774b0d96669a02c5d07fdc07c83e6 to your computer and use it in GitHub Desktop.
wait condition
console.log('Waiting for job completion in step "' + request.name + '"');
// Construct our request URL from environment variables
var url = `http://${pm.environment.get('wiremock')}/__admin/requests`;
var retryDelay = 2000;
var retryLimit = 10;
function isProcessingComplete(retryCount) {
pm.sendRequest(url, function (err, response) {
if(err) {
// hmmm. Should I keep trying or fail this run? Just log it for now.
console.log(err);
} else {
// I could also check for response.json().results.length > 0, but that
// would omit SUCCESS with empty results which may be valid
if(response.json().meta.total < 1) {
if (retryCount < retryLimit) {
console.log('Job is still PENDING. Retrying in ' + retryDelay + 'ms');
setTimeout(function() {
isProcessingComplete(++retryCount);
}, retryDelay);
} else {
console.log('Retry limit reached, giving up.');
postman.setNextRequest(null);
}
}
}
});
}
isProcessingComplete(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment