Skip to content

Commit

Permalink
show a progress bar to inform end-user about the current status
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Sep 29, 2017
1 parent 75faaaf commit 79ba68d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -71,6 +72,12 @@ public class QuickDiskUsagePlugin extends Plugin {

private long lastRunEnd = 0;

protected AtomicInteger progress = new AtomicInteger();

protected AtomicInteger total = new AtomicInteger();



@Override
public void start() throws Exception {
try {
Expand Down Expand Up @@ -169,6 +176,7 @@ public void onCompleted(Path dir, long usage) {
jobsUsages.remove(jobDiskItem);
}
jobsUsages.add(jobDiskItem);
progress.incrementAndGet();
}
}

Expand All @@ -186,6 +194,7 @@ public void onCompleted(Path dir, long usage) {
directoriesUsages.remove(diskItem);
}
directoriesUsages.add(diskItem);
progress.incrementAndGet();
}
}

Expand Down Expand Up @@ -243,9 +252,20 @@ private void registerDirectories(UsageComputation uc) throws IOException, Interr
}
}


public int getItemsCount() {
return total.intValue();
}

public int getProgress() {
return progress.intValue();
}

private transient final Runnable computeDiskUsage = new Runnable() {

public void run() {
logger.info("Re-estimating disk usage");
progress.set(0);
lastRunStart = System.currentTimeMillis();
SecurityContext impersonate = ACL.impersonate(ACL.SYSTEM);
// TODO switch to Jenkins.getActiveInstance() once 1.590+ is the baseline
Expand All @@ -257,6 +277,7 @@ public void run() {
UsageComputation uc = new UsageComputation(Arrays.asList(Paths.get(System.getProperty("java.io.tmpdir")), jenkins.getRootDir().toPath()));
registerJobs(uc);
registerDirectories(uc);
total.set(uc.getItemsCount());
uc.compute();
logger.info("Finished re-estimating disk usage.");
lastRunEnd = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public void addListener(Path path, CompletionListener listener) {
listenerMap.put(path.toAbsolutePath(), listener);
}

public int getItemsCount() {
return listenerMap.size();
}

public void compute() throws IOException {
for (Path path : pathsToScan) {
computeUsage(path.toAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<j:when test="${it.running}">
<strong>Update in progress</strong>, please
<a href=".">try again in a short while</a>
<br/>
<progress value="${it.progress}" max="${it.itemsCount}"/>
<br/>
</j:when>
<j:otherwise>
Computed ${it.since} ago. Took ${it.duration}.
Expand Down

0 comments on commit 79ba68d

Please sign in to comment.