Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Queue.schedule2 to allow the caller to retrieve the existing item in the queue. AbstractProject.doBuild() changed the behavior a bit to reply 201 if the item was already found in the queue (instead of a new one created.)
- Loading branch information
Showing
6 changed files
with
221 additions
and
38 deletions.
There are no files selected for viewing
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
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
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
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
111 changes: 111 additions & 0 deletions
111
core/src/main/java/hudson/model/queue/ScheduleResult.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,111 @@ | ||
package hudson.model.queue; | ||
|
||
import hudson.model.Action; | ||
import hudson.model.Queue; | ||
import hudson.model.Queue.Item; | ||
import hudson.model.Queue.Task; | ||
import hudson.model.Queue.WaitingItem; | ||
|
||
/** | ||
* Result of {@link Queue#schedule2} | ||
* | ||
* @author Kohsuke Kawaguchi | ||
* @since 1.521 | ||
* @see Queue#schedule(Task, int, Action...) | ||
*/ | ||
public abstract class ScheduleResult { | ||
|
||
/** | ||
* If true, the {@link #getItem()} is newly created | ||
* as a result of {@link Queue#schedule2}. | ||
*/ | ||
public boolean isCreated() { | ||
return false; | ||
} | ||
|
||
/** | ||
* The scheduling of the task was refused and the queue didn't change. | ||
* If this method returns true, {@link #getItem()} will return null. | ||
*/ | ||
public boolean isRefused() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Unless {@link #isRefused()} is true, this method either returns | ||
* the newly created item in the queue or the existing item that's already | ||
* in the queue that matched the submitted task. | ||
*/ | ||
public Item getItem() { | ||
return null; | ||
} | ||
|
||
/** | ||
* If {@link #isCreated()} returns true, then this method returns | ||
* the newly created item, which is always of the type {@link WaitingItem}. | ||
*/ | ||
public WaitingItem getCreateItem() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Opposite of {@link #isRefused()} | ||
*/ | ||
public final boolean isAccepted() { | ||
return !isRefused(); | ||
} | ||
|
||
public static final class Created extends ScheduleResult { | ||
private final WaitingItem item; | ||
private Created(WaitingItem item) { | ||
this.item = item; | ||
} | ||
|
||
@Override | ||
public boolean isCreated() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public WaitingItem getCreateItem() { | ||
return item; | ||
} | ||
|
||
@Override | ||
public Item getItem() { | ||
return item; | ||
} | ||
} | ||
|
||
public static final class Existing extends ScheduleResult { | ||
private final Item item; | ||
|
||
private Existing(Item item) { | ||
this.item = item; | ||
} | ||
|
||
@Override | ||
public Item getItem() { | ||
return item; | ||
} | ||
} | ||
|
||
public static final class Refused extends ScheduleResult { | ||
@Override | ||
public boolean isRefused() { | ||
return true; | ||
} | ||
} | ||
|
||
public static Created created(WaitingItem i) { | ||
return new Created(i); | ||
} | ||
|
||
public static Existing existing(Item i) { | ||
return new Existing(i); | ||
} | ||
|
||
public static Refused refused() { | ||
return new Refused(); | ||
} | ||
} |
Oops, something went wrong.