Skip to content

Commit

Permalink
[JENKINS-39072] Print log messages about what is happening with timeo…
Browse files Browse the repository at this point in the history
…uts.
  • Loading branch information
jglick committed Oct 18, 2016
1 parent 2cbd8fd commit f36a5c3
Showing 1 changed file with 13 additions and 3 deletions.
Expand Up @@ -2,6 +2,8 @@

import com.google.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Util;
import hudson.model.TaskListener;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

Expand All @@ -15,6 +17,7 @@
public class TimeoutStepExecution extends AbstractStepExecutionImpl {
@Inject(optional=true)
private transient TimeoutStep step;
@StepContextParameter private transient TaskListener listener;
private BodyExecution body;
private transient ScheduledFuture<?> killer;

Expand Down Expand Up @@ -45,17 +48,24 @@ public void onResume() {
*/
private void setupTimer(final long now) {
if (end > now) {
long delay = end - now;
listener.getLogger().println("Timeout set to expire in " + Util.getTimeSpanString(delay));
killer = Timer.get().schedule(new Runnable() {
@Override
public void run() {
body.cancel(new ExceededTimeout());
cancel();
}
}, end - now, TimeUnit.MILLISECONDS);
}, delay, TimeUnit.MILLISECONDS);
} else {
body.cancel(new ExceededTimeout());
cancel();
}
}

private void cancel() {
listener.getLogger().println("Cancelling nested steps due to timeout");
body.cancel(new ExceededTimeout());
}

@Override
public void stop(Throwable cause) throws Exception {
if (body!=null)
Expand Down

0 comments on commit f36a5c3

Please sign in to comment.