Skip to content

Commit

Permalink
[JENKINS-44981] Action for tracking node block queued/running status
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Jun 20, 2017
1 parent 7f15c15 commit 779e794
Showing 1 changed file with 79 additions and 0 deletions.
@@ -0,0 +1,79 @@
package org.jenkinsci.plugins.workflow.actions;

import hudson.model.InvisibleAction;
import org.jenkinsci.plugins.workflow.graph.FlowNode;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* Records information for a {@code node} block.
*
* TODO: Decide whether this is general enough that it should move to workflow-support alongside
* {@link org.jenkinsci.plugins.workflow.support.actions.WorkspaceActionImpl}.
*/
public class ExecutorTaskInfoAction extends InvisibleAction implements FlowNodeAction, PersistentAction {
private static final long serialVersionUID = 1;

private String whyBlocked;
private boolean launched;
// Initialized at -1 for "not started yet".
private long whenStartedOrCanceled = -1L;

private transient FlowNode parent;

public ExecutorTaskInfoAction(FlowNode parent) {
this.parent = parent;
}

public ExecutorTaskInfoAction(@Nonnull String whyBlocked, FlowNode parent) {
this(parent);
this.whyBlocked = whyBlocked;
}

public FlowNode getParent() {
return parent;
}

@Override
public void onLoad(FlowNode parent) {
this.parent = parent;
}

void setLaunched() {
// Because we're not blocked any more at this point!
this.whyBlocked = null;
this.whenStartedOrCanceled = System.currentTimeMillis();
this.launched = true;
}

void setWhyBlocked(@Nonnull String whyBlocked) {
this.whyBlocked = whyBlocked;
}

@CheckForNull
public String getWhyBlocked() {
return whyBlocked;
}

public long getWhenStartedOrCanceled() {
return whenStartedOrCanceled;
}

void cancelTask() {
this.whyBlocked = null;
this.whenStartedOrCanceled = System.currentTimeMillis();
}

public boolean isQueued() {
return whyBlocked != null && whenStartedOrCanceled == -1;
}

public boolean isLaunched() {
return launched;
}

public boolean isCanceled() {
return !launched && whyBlocked == null && whenStartedOrCanceled > -1;
}
}

0 comments on commit 779e794

Please sign in to comment.