Created
June 20, 2018 12:20
-
-
Save a-chumagin/76b774b0d96669a02c5d07fdc07c83e6 to your computer and use it in GitHub Desktop.
wait condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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