Skip to content

Commit

Permalink
Tuned the waiting: added some randomness, and wait a bit longer each …
Browse files Browse the repository at this point in the history
…time, with 20 secs and a bit as maximum. Also minitor task redirects.
  • Loading branch information
egonw committed Aug 23, 2011
1 parent 05c851c commit 29f0a4b
Showing 1 changed file with 12 additions and 2 deletions.
Expand Up @@ -47,19 +47,25 @@ public static String calculate(String service, String model, String dataSetURI)
// FIXME: I should really start using the RDF response...
String responseString = method.getResponseBodyAsString();
logger.debug("Status: " + status);
int tailing = 1;
if (status == 200 || status == 202) {
if (responseString.contains("/task/")) {
// OK, we got a task... let's wait until it is done
String task = responseString;
logger.debug("response: " + task);
Thread.sleep(1000); // let's be friendly, and wait 1 sec
Thread.sleep(andABit(500)); // let's be friendly, and wait 1 sec
TaskState state = Task.getState(task);
while (!state.isFinished()) {
Thread.sleep(3000); // let's be friendly, and wait 3 sec
// let's be friendly, and wait 2 secs and a bit and increase
// that time after each wait
Thread.sleep(andABit(2000*tailing));
state = Task.getState(task);
if (state.isRedirected()) {
task = state.getResults();
logger.debug("Got a Task redirect. New task:" + task);
}
// but wait at most 20 secs and a bit
if (tailing < 10) tailing++;
}
// OK, it should be finished now
dataset = state.getResults();
Expand All @@ -76,4 +82,8 @@ public static String calculate(String service, String model, String dataSetURI)
return dataset;
}

private static int andABit(int minimum) {
return (minimum + (int)Math.round(minimum*Math.random()));
}

}

0 comments on commit 29f0a4b

Please sign in to comment.