From 3b00d9cc4a43c37a2608fc48f1f9580872168130 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 21 Apr 2007 14:10:25 +0000 Subject: [PATCH] bug fix. executor list was not displaying things correctly. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3184 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/model/AbstractBuild.java | 2 +- .../java/hudson/model/AbstractProject.java | 4 ++-- core/src/main/java/hudson/model/Executor.java | 19 ++++++++++--------- core/src/main/java/hudson/model/Queue.java | 14 +++++++++++++- core/src/main/java/hudson/model/Run.java | 2 +- .../main/resources/lib/hudson/executors.jelly | 4 ++-- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 4eaeec27d1..16671c5a1b 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -39,7 +39,7 @@ import java.util.ArrayList; * @author Kohsuke Kawaguchi * @see AbstractProject */ -public abstract class AbstractBuild

,R extends AbstractBuild> extends Run implements Runnable { +public abstract class AbstractBuild

,R extends AbstractBuild> extends Run implements Queue.Executable { /** * PluginName of the slave this project was built on. diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 919c8a75d3..dbff795b3f 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -314,8 +314,8 @@ public abstract class AbstractProject

,R extends A return duration; } - public void execute() throws IOException { - newBuild().run(); + public R createExecutable() throws IOException { + return newBuild(); } public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException { diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java index cf9dc107fb..51ceff2807 100644 --- a/core/src/main/java/hudson/model/Executor.java +++ b/core/src/main/java/hudson/model/Executor.java @@ -17,14 +17,13 @@ public class Executor extends Thread { private final Computer owner; private final Queue queue; - private Queue.Task task; - private long startTime; /** * Executor number that identifies it among other executors for the same {@link Computer}. */ private int number; + private Queue.Executable executable; public Executor(Computer owner) { super("Executor #"+owner.getExecutors().size()+" for "+owner.getDisplayName()); @@ -47,6 +46,7 @@ public class Executor extends Thread { } } + Queue.Task task; try { task = queue.pop(); } catch (InterruptedException e) { @@ -55,14 +55,15 @@ public class Executor extends Thread { try { startTime = System.currentTimeMillis(); - task.execute(); + executable = task.createExecutable(); + executable.run(); } catch (Throwable e) { // for some reason the executor died. this is really // a bug in the code, but we don't want the executor to die, // so just leave some info and go on to build other things e.printStackTrace(); } - task = null; + executable = null; } } @@ -72,8 +73,8 @@ public class Executor extends Thread { * @return * null if the executor is idle. */ - public Queue.Task getCurrentTask() { - return task; + public Queue.Executable getCurrentExecutable() { + return executable; } /** @@ -91,7 +92,7 @@ public class Executor extends Thread { * Returns true if this {@link Executor} is ready for action. */ public boolean isIdle() { - return task==null; + return executable==null; } /** @@ -101,7 +102,7 @@ public class Executor extends Thread { * if it's impossible to estimate the progress. */ public int getProgress() { - long d = task.getEstimatedDuration(); + long d = executable.getParent().getEstimatedDuration(); if(d<0) return -1; int num = (int)((System.currentTimeMillis()-startTime)*100/d); @@ -114,7 +115,7 @@ public class Executor extends Thread { * until the build completes. */ public String getEstimatedRemainingTime() { - long d = task.getEstimatedDuration(); + long d = executable.getParent().getEstimatedDuration(); if(d<0) return "N/A"; long eta = d-(System.currentTimeMillis()-startTime); diff --git a/core/src/main/java/hudson/model/Queue.java b/core/src/main/java/hudson/model/Queue.java index 45080d4f4a..5b9fb14d40 100644 --- a/core/src/main/java/hudson/model/Queue.java +++ b/core/src/main/java/hudson/model/Queue.java @@ -506,7 +506,19 @@ public class Queue { */ long getEstimatedDuration(); - void execute() throws IOException; + Executable createExecutable() throws IOException; + } + + public interface Executable extends Runnable { + /** + * Task from which this executable was created. + */ + Task getParent(); + + /** + * Called by {@link Executor} to perform the task + */ + void run(); } /** diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 7bc658276d..0ccd2c3583 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -209,7 +209,7 @@ public abstract class Run ,RunT extends Run -

Building ${e.currentTask}
- +
Building ${e.currentExecutable}
+ -- GitLab