Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8 from jglick/sleep-info-JENKINS-34281
[JENKINS-34281] Indicate if we are still sleeping after a resume
  • Loading branch information
jglick committed Jun 9, 2016
2 parents 7360c8d + 3da248c commit f79ae94
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 f79ae94

Please sign in to comment.