Skip to content

Commit bc61f7f

Browse files
authored
Add upload progress reporting (#313)
1 parent 2d7f482 commit bc61f7f

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
* Upload progress reporting ([#313](https://github.com/heroku/heroku-jvm-application-deployer/pull/313))
1013

1114
## [4.0.4] - 2024-04-03
1215

src/main/java/com/heroku/deployer/deployment/Deployer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public static boolean deploy(String apiKey, String clientName, String clientVers
4040
}
4141

4242
System.out.println("-----> Uploading build...");
43-
uploadSourceBlob(deploymentDescriptor.getSourceBlobPath(), URI.create(sourceBlob.getPutUrl()), (currentBytes, totalBytes) -> {});
44-
System.out.println(" - success");
43+
long uploadStartMillis = System.currentTimeMillis();
44+
uploadSourceBlob(deploymentDescriptor.getSourceBlobPath(), URI.create(sourceBlob.getPutUrl()), new UploadProgressReporter());
45+
System.out.printf(" - success (%.1f seconds)\n", (float) (System.currentTimeMillis() - uploadStartMillis) / 1000.0f);
4546

4647
List<String> buildpacks = deploymentDescriptor.getBuildpacks();
4748
if (buildpacks.isEmpty()) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.heroku.deployer.deployment;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import java.util.function.BiConsumer;
5+
6+
public final class UploadProgressReporter implements BiConsumer<Long, Long> {
7+
private long lastOutput;
8+
private long lastBytes;
9+
10+
@Override
11+
public void accept(Long currentBytes, Long totalBytes) {
12+
if (System.currentTimeMillis() - lastOutput > 1000) {
13+
System.out.printf(" Uploaded %s/%s (%.1f%%, %s/s)\n",
14+
FileUtils.byteCountToDisplaySize(currentBytes),
15+
FileUtils.byteCountToDisplaySize(totalBytes),
16+
((float) currentBytes / (float) totalBytes) * 100.0,
17+
FileUtils.byteCountToDisplaySize(currentBytes - lastBytes)
18+
);
19+
20+
lastOutput = System.currentTimeMillis();
21+
lastBytes = currentBytes;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)