-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JENKINS-23368 - Enforce start interval/delay between running builds. #21
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import hudson.model.Executor; | ||
import hudson.model.Hudson; | ||
import hudson.model.Node; | ||
import hudson.model.Run; | ||
import hudson.model.Queue; | ||
import hudson.model.Queue.Task; | ||
import hudson.model.labels.LabelAtom; | ||
|
@@ -139,6 +140,26 @@ public CauseOfBlockage canRun(Task task, ThrottleJobProperty tjp) { | |
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_MaxCapacityTotal(totalRunCount)); | ||
} | ||
} | ||
|
||
// check start interval between runs | ||
if (tjp.getStartInterval().longValue() > 0) { | ||
if (task instanceof AbstractProject) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may support other Job types, needs to be checked |
||
AbstractProject<?,?> p = (AbstractProject<?,?>) task; | ||
Run<?,?> lastBuild = p.getLastBuild(); | ||
if (null != lastBuild && lastBuild.isBuilding()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lastBuild is not helpful for concurrent runs, because there may be other running builds. 🐜 |
||
|
||
// Probably better to use lastBuild.getStartTimeInMillis() which was introduced in Jenkins 1.494. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The core dependency has been bumped, hence it can be updated now |
||
// We are building against 1.424 so getTimeInMillis() is an OK approximation | ||
long timeSinceLastBuildStartedInSeconds = (System.currentTimeMillis() - lastBuild.getTimeInMillis()) / 1000; | ||
long remainingIntervalSeconds = tjp.getStartInterval().longValue() - timeSinceLastBuildStartedInSeconds; | ||
if(remainingIntervalSeconds > 0) { | ||
long minutes = remainingIntervalSeconds / 60; | ||
long seconds = remainingIntervalSeconds % 60; | ||
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_StartIntervalLimit(minutes, seconds)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// If the project is in one or more categories... | ||
else if (tjp.getThrottleOption().equals("category")) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
ThrottleQueueTaskDispatcher.MaxCapacityOnNode=Already running {0} builds on node | ||
ThrottleQueueTaskDispatcher.MaxCapacityTotal=Already running {0} builds across all nodes | ||
ThrottleQueueTaskDispatcher.BuildPending=A build is pending launch | ||
|
||
ThrottleMatrixProjectOptions.DisplayName=Additional options for Matrix projects | ||
ThrottleQueueTaskDispatcher.StartIntervalLimit=Waiting for required start interval. [{0}m {1}s] | ||
ThrottleMatrixProjectOptions.DisplayName=Additional options for Matrix projects |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,10 @@ | |
field="maxConcurrentPerNode"> | ||
<f:textbox /> | ||
</f:entry> | ||
<f:entry title="${%Minimum Start Interval between Builds in seconds}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about introducing an "Advanced" section for such option? |
||
field="startInterval"> | ||
<f:textbox /> | ||
</f:entry> | ||
<j:if test="${!empty(descriptor.categories)}"> | ||
<f:entry title="${%Multi-Project Throttle Category}"> | ||
<j:forEach var="cat" items="${descriptor.categories}"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An old constructor is also required for the backward compatibility