Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour committed Dec 3, 2024
1 parent 7b86c54 commit 6640a0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void init() {
this.pauseBuildAgentTopic = hazelcastInstance.getTopic("pauseBuildAgentTopic");
this.resumeBuildAgentTopic = hazelcastInstance.getTopic("resumeBuildAgentTopic");
this.buildAgentInformation.addEntryListener(new BuildAgentListener(), false);
this.getBuildAgentsCapacity();
this.updateBuildAgentCapacity();
}

/**
Expand Down Expand Up @@ -341,7 +341,7 @@ public Page<BuildJob> getFilteredFinishedBuildJobs(FinishedBuildJobPageableSearc
* @param participationId the ID of the participation for which the queue release date is estimated
* @return the estimated queue release date as a {@link ZonedDateTime}
*/
public ZonedDateTime getBuildJobEstimatedQueueDuration(long participationId) {
public ZonedDateTime getBuildJobEstimatedStartDate(long participationId) {
if (queue.isEmpty() || this.buildAgentsCapacity > this.runningBuildJobCount + queue.size()) {
return ZonedDateTime.now();
}
Expand All @@ -356,7 +356,7 @@ public ZonedDateTime getBuildJobEstimatedQueueDuration(long participationId) {

ZonedDateTime now = ZonedDateTime.now();

List<Long> agentsAvailabilities = new ArrayList<>(getQueuedJobs().stream().map(job -> buildJobRemainingDuration(job, now)).sorted().toList());
List<Long> agentsAvailabilities = new ArrayList<>(getQueuedJobs().stream().map(job -> getBuildJobRemainingDuration(job, now)).sorted().toList());

if (agentsAvailabilities.size() < this.buildAgentsCapacity) {
int agentsToAdd = this.buildAgentsCapacity - agentsAvailabilities.size();
Expand Down Expand Up @@ -396,7 +396,7 @@ private Long calculateNextJobQueueDuration(List<Long> agentsAvailabilities, List
return agentRemainingTimeObj == null ? 0 : agentRemainingTimeObj;
}

private long buildJobRemainingDuration(BuildJobQueueItem buildJob, ZonedDateTime now) {
private long getBuildJobRemainingDuration(BuildJobQueueItem buildJob, ZonedDateTime now) {
ZonedDateTime estimatedCompletionDate = buildJob.jobTimingInfo().estimatedCompletionDate();
if (estimatedCompletionDate == null) {
return 0;
Expand All @@ -414,23 +414,23 @@ private class BuildAgentListener
@Override
public void entryAdded(com.hazelcast.core.EntryEvent<String, BuildAgentInformation> event) {
log.debug("Build agent added: {}", event.getValue());
getBuildAgentsCapacity();
updateBuildAgentCapacity();
}

@Override
public void entryRemoved(com.hazelcast.core.EntryEvent<String, BuildAgentInformation> event) {
log.debug("Build agent removed: {}", event.getOldValue());
getBuildAgentsCapacity();
updateBuildAgentCapacity();
}

@Override
public void entryUpdated(com.hazelcast.core.EntryEvent<String, BuildAgentInformation> event) {
log.debug("Build agent updated: {}", event.getValue());
getBuildAgentsCapacity();
updateBuildAgentCapacity();
}
}

private void getBuildAgentsCapacity() {
private void updateBuildAgentCapacity() {
buildAgentsCapacity = getBuildAgentInformation().stream().mapToInt(BuildAgentInformation::maxNumberOfConcurrentBuildJobs).sum();
runningBuildJobCount = getBuildAgentInformation().stream().mapToInt(BuildAgentInformation::numberOfCurrentBuildJobs).sum();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,19 @@ public ResponseEntity<BuildJobsStatisticsDTO> getBuildJobStatistics(@PathVariabl
}

/**
* Returns the estimated queue duration for a build job.
* Returns the estimated start date of the build job for the given participation.
*
* @param participationId the id of the participation
* @return the estimated queue duration
*/
@GetMapping("queued-jobs/queue-duration-estimation")
@EnforceAtLeastStudent
public ResponseEntity<ZonedDateTime> getBuildJobQueueDurationEstimation(@RequestParam long participationId) {
public ResponseEntity<ZonedDateTime> getBuildJobEstimatedStartDate(@RequestParam long participationId) {
var start = System.nanoTime();
if (participationId <= 0) {
ResponseEntity.badRequest().build();
}
ZonedDateTime estimatedJobQueueReleaseTime = localCIBuildJobQueueService.getBuildJobEstimatedQueueDuration(participationId);
ZonedDateTime estimatedJobQueueReleaseTime = localCIBuildJobQueueService.getBuildJobEstimatedStartDate(participationId);
log.debug("Queue duration estimation took {} ms", TimeLogUtil.formatDurationFrom(start));
return ResponseEntity.ok(estimatedJobQueueReleaseTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void testBuildJob() throws Exception {
agent1 = new BuildAgentInformation(buildAgent, 2, 2, new ArrayList<>(List.of(job1, job2)), BuildAgentInformation.BuildAgentStatus.ACTIVE, null, null);
buildAgentInformation.put(buildAgent.memberAddress(), agent1);

var queueDurationEstimation = sharedQueueManagementService.getBuildJobEstimatedQueueDuration(job4.participationId());
var queueDurationEstimation = sharedQueueManagementService.getBuildJobEstimatedStartDate(job4.participationId());
assertThat(queueDurationEstimation).isCloseTo(now.plusSeconds(48), within(1, ChronoUnit.SECONDS));
}
}

0 comments on commit 6640a0e

Please sign in to comment.