Skip to content

Commit

Permalink
[JENKINS-34281] Indicate if we are still sleeping after a resume.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jun 8, 2016
1 parent 7360c8d commit 3da248c
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -26,6 +26,8 @@

import com.google.inject.Inject;
import hudson.Extension;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.util.ListBoxModel;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -60,6 +62,7 @@ public static final class Execution extends AbstractStepExecutionImpl {
private static final long serialVersionUID = 1L;

@Inject(optional=true) private transient SleepStep step;
@StepContextParameter private transient TaskListener listener;
private long end;
private transient volatile ScheduledFuture<?> task;

Expand All @@ -72,12 +75,14 @@ public static final class Execution extends AbstractStepExecutionImpl {

private void setupTimer(long now) {
if (end > now) {
listener.getLogger().println("Sleeping for " + Util.getTimeSpanString(end - now));
task = Timer.get().schedule(new Runnable() {
@Override public void run() {
getContext().onSuccess(null);
}
}, end - now, TimeUnit.MILLISECONDS);
} else {
listener.getLogger().println("No need to sleep any longer");
getContext().onSuccess(null);
}
}
Expand Down

0 comments on commit 3da248c

Please sign in to comment.