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

Add upload progress reporting #313

Merged
merged 1 commit into from
May 6, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* Upload progress reporting ([#313](https://github.com/heroku/heroku-jvm-application-deployer/pull/313))

## [4.0.4] - 2024-04-03

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/heroku/deployer/deployment/Deployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public static boolean deploy(String apiKey, String clientName, String clientVers
}

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

List<String> buildpacks = deploymentDescriptor.getBuildpacks();
if (buildpacks.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.heroku.deployer.deployment;

import org.apache.commons.io.FileUtils;
import java.util.function.BiConsumer;

public final class UploadProgressReporter implements BiConsumer<Long, Long> {
private long lastOutput;
private long lastBytes;

@Override
public void accept(Long currentBytes, Long totalBytes) {
if (System.currentTimeMillis() - lastOutput > 1000) {
System.out.printf(" Uploaded %s/%s (%.1f%%, %s/s)\n",
FileUtils.byteCountToDisplaySize(currentBytes),
FileUtils.byteCountToDisplaySize(totalBytes),
((float) currentBytes / (float) totalBytes) * 100.0,
FileUtils.byteCountToDisplaySize(currentBytes - lastBytes)
);

lastOutput = System.currentTimeMillis();
lastBytes = currentBytes;
}
}
}