Fix: download progress indicator jumping back and forth

This commit is contained in:
Sheepit Renderfarm
2024-11-20 16:57:43 +00:00
parent 8d7a29cf7f
commit 3d4c9a0487
7 changed files with 55 additions and 33 deletions

View File

@@ -796,15 +796,15 @@ import okhttp3.HttpUrl;
return err;
}
private Error.Type downloadChunks(List<Chunk> chunks, String status) throws SheepItException {
int threads = Math.max(1, Math.min(chunks.size(), 12)); // at least one thread, to avoid IllegalArgumentException if total = 0
private Error.Type downloadChunks(DownloadItem downloadInfos, String status) throws SheepItException {
int threads = Math.max(1, Math.min(downloadInfos.getChunks().size(), 12)); // at least one thread, to avoid IllegalArgumentException if total = 0
ExecutorService executor = Executors.newFixedThreadPool(threads);
List<Callable<Error.Type>> tasks = new ArrayList<>();
this.gui.getDownloadProgress().reset(status);
this.gui.getDownloadProgress().reset(status, downloadInfos.getTotalSize());
for (Chunk chunk : chunks) {
for (Chunk chunk : downloadInfos.getChunks()) {
Callable<Type> downloadTask = () -> {
DownloadManager downloadManager = new DownloadManager(
this.server,
@@ -842,11 +842,11 @@ import okhttp3.HttpUrl;
}
protected Error.Type downloadSceneFile(Job ajob) throws SheepItException {
return this.downloadChunks(ajob.getArchiveChunks(), "Downloading Project");
return this.downloadChunks(ajob.getProjectDownload(), "Downloading Project");
}
protected Error.Type downloadExecutable(Job ajob) throws SheepItException {
return this.downloadChunks(ajob.getRendererChunks(), "Downloading Blender");
return this.downloadChunks(ajob.getRendererDownload(), "Downloading Blender");
}
protected void removeSceneDirectory(Job ajob) {
@@ -860,7 +860,7 @@ import okhttp3.HttpUrl;
File rendererPathFile = new File(rendererPath);
// chunk files are already downloaded, either on shared directory or cache directory
for (Chunk chunk: Utils.concatWithCollection(ajob.getRendererChunks(), ajob.getArchiveChunks())) {
for (Chunk chunk: Utils.concatWithCollection(ajob.getRendererDownload().getChunks(), ajob.getProjectDownload().getChunks())) {
if (this.directoryManager.isSharedEnabled() && new File(this.directoryManager.getSharedPathFor(chunk)).exists()) {
this.gui.status("Copying chunk from common directory");
if (this.directoryManager.copyChunkFromSharedToCache(chunk) == false) {
@@ -878,7 +878,7 @@ import okhttp3.HttpUrl;
this.log.debug("Client::prepareWorkingDirectory Extracting renderer into " + rendererPath);
// unzip the archive
ret = Utils.unzipChunksIntoDirectory(ajob.getRendererChunks().stream().map(chunk -> this.directoryManager.getCachePathFor(chunk)).collect(Collectors.toList()), rendererPath, null, log);
ret = Utils.unzipChunksIntoDirectory(ajob.getRendererDownload().getChunks().stream().map(chunk -> this.directoryManager.getCachePathFor(chunk)).collect(Collectors.toList()), rendererPath, null, log);
if (ret != 0) {
this.log.error("Client::prepareWorkingDirectory, error(1) with Utils.unzipChunksIntoDirectory(" + rendererPath + ") returned " + ret);
this.gui.error(String.format("Unable to extract the renderer (error %d)", ret));
@@ -906,14 +906,14 @@ import okhttp3.HttpUrl;
Instant startUnzip = Instant.now();
ret = Utils.unzipChunksIntoDirectory(
ajob.getArchiveChunks().stream().map(chunk -> this.directoryManager.getCachePathFor(chunk)).collect(Collectors.toList()),
ajob.getProjectDownload().getChunks().stream().map(chunk -> this.directoryManager.getCachePathFor(chunk)).collect(Collectors.toList()),
scenePath,
ajob.getPassword(),
log);
Instant stopUnzip = Instant.now();
Duration unzipDuration = Duration.between(startUnzip, stopUnzip);
log.debug("Unzipping " + ajob.getArchiveChunks().size() + " chunks of \"" + ajob.getName() + "\" took " + unzipDuration.toSeconds() + "s");
log.debug("Unzipping " + ajob.getProjectDownload().getChunks().size() + " chunks of \"" + ajob.getName() + "\" took " + unzipDuration.toSeconds() + "s");
if (ret != 0) {
this.log.error("Client::prepareWorkingDirectory, error(2) with Utils.unzipChunksIntoDirectory returned " + ret);