Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-44981] Action for tracking node block queued/running status
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/org/jenkinsci/plugins/workflow/actions/ExecutorTaskInfoAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |