Skip to content

Commit

Permalink
add estimated percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
InventivetalentDev committed Sep 5, 2023
1 parent fbf4f35 commit 184a150
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions org.inventivetalent.teamcity.sdPlugin/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const action = {
this.refreshUser().then(() => {
if (!this.currentUser) return;

this.clearAndSetInterval('allRefresh', () => this.refreshAllBuilds(), 8000);
this.clearAndSetInterval('allRefresh', () => this.refreshAllBuilds(), 6000 + Math.random() * 100);
this.refreshAllBuilds();
});

Expand Down Expand Up @@ -168,6 +168,7 @@ const action = {
let build = this.runningBuilds[Object.keys(this.runningBuilds)[0]];
console.log("build", build);
if (build) {

name = build.buildType.name;
branch = build.branchName || "";

Expand All @@ -177,13 +178,20 @@ const action = {
let duration = moment.duration(moment(build.finishEstimate).diff(moment()))
status = "" + duration.seconds() + "s";
} else if (build.percentageComplete) {
status = "" + build.percentageComplete + "%";
if (!build.estimatedPercentageComplete || build.percentageComplete > build.estimatedPercentageComplete) {
build.estimatedPercentageComplete = build.percentageComplete;
}
if (build.percentPerSecond) {
build.estimatedPercentageComplete += build.percentPerSecond / 2;
}

status = "" + Math.round(build.estimatedPercentageComplete) + "%";
} else {
status = build.state;
}


this.clearAndSetTimeout("render", () => this.render(), 1000);
this.clearAndSetTimeout("render", () => this.render(), 500);
}
}

Expand Down Expand Up @@ -234,7 +242,16 @@ const action = {
for (let id in this.runningBuilds) {
let runningBuild = this.runningBuilds[id];
promises.push(this.getBuildById(runningBuild.id).then(build => {
runningBuild = {...{}, ...runningBuild, ...build};
runningBuild = { ...{}, ...runningBuild, ...build };

if (!runningBuild.lastPercentageComplete) {
runningBuild.lastPercentageComplete = runningBuild.percentageComplete;
runningBuild.lastRefresh = Date.now();
}
runningBuild.percentPerSecond = (runningBuild.percentageComplete - runningBuild.lastPercentageComplete) / ((Date.now() - runningBuild.lastRefresh) / 1000);
runningBuild.lastRefresh = Date.now();
runningBuild.lastPercentageComplete = runningBuild.percentageComplete;

this.runningBuilds[id] = runningBuild;
if (runningBuild.running) {
stillRunning++;
Expand Down

0 comments on commit 184a150

Please sign in to comment.