Skip to content

Commit 0939c91

Browse files
committed
Pretty print timeout when (uh) timing out an entry in the queue
1 parent a6b5f22 commit 0939c91

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

java/server/src/org/openqa/selenium/grid/sessionqueue/local/LocalNewSessionQueue.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ public class LocalNewSessionQueue extends NewSessionQueue {
7474
private final ScheduledExecutorService executorService =
7575
Executors.newSingleThreadScheduledExecutor();
7676
private final Thread shutdownHook = new Thread(this::callExecutorShutdown);
77-
private final String timedOutErrorMessage =
78-
String.format( "New session request rejected after being in the queue for more than %s",
79-
requestTimeout);
77+
private final String timedOutErrorMessage = String.format(
78+
"New session request rejected after being in the queue for more than %s",
79+
format(requestTimeout));
8080

81-
public LocalNewSessionQueue(Tracer tracer, EventBus bus, Duration retryInterval,
82-
Duration requestTimeout) {
81+
public LocalNewSessionQueue(
82+
Tracer tracer,
83+
EventBus bus,
84+
Duration retryInterval,
85+
Duration requestTimeout) {
8386
super(tracer, retryInterval, requestTimeout);
8487
this.bus = Require.nonNull("Event bus", bus);
8588
Runtime.getRuntime().addShutdownHook(shutdownHook);
@@ -301,5 +304,21 @@ public void callExecutorShutdown() {
301304
LOG.info("Shutting down session queue executor service");
302305
executorService.shutdown();
303306
}
307+
308+
private static String format(Duration duration) {
309+
long hours = duration.toHours();
310+
int minutes = (int) duration.toMinutes() % 60;
311+
int secs = (int) (duration.getSeconds() % 60);
312+
313+
StringBuilder toReturn = new StringBuilder();
314+
if (hours != 0) {
315+
toReturn.append(hours).append("h ");
316+
}
317+
if (hours != 0 || minutes != 0) {
318+
toReturn.append(minutes).append("m ");
319+
}
320+
toReturn.append(secs).append("s");
321+
return toReturn.toString();
322+
}
304323
}
305324

0 commit comments

Comments
 (0)