Created
December 20, 2012 09:22
-
-
Save anonymous/4344091 to your computer and use it in GitHub Desktop.
script to wait until the resource is ready state.
This file contains hidden or 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
// requires classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' | |
/** | |
* Wait until the resource is ready state. | |
*/ | |
def waitUntilResourceIsReady(String resource) { | |
def http = new groovyx.net.http.HTTPBuilder(resource) | |
def check = { | |
try { | |
http.get(contentType: groovyx.net.http.ContentType.TEXT) | |
true | |
} catch(IOException e) { | |
logger.warn "Waiting for ${resource}: ${e.localizedMessage}" | |
false | |
} | |
} | |
Thread.sleep(1000L) | |
while (!check()) { | |
Thread.sleep(1000L) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment