Forked from anonymous/waitUntilResourceIsReady.groovy
Created
December 20, 2012 09:23
-
-
Save int128/4344103 to your computer and use it in GitHub Desktop.
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