Skip to content
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

show a progress bar to inform end-user about the current status #23

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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