|
44 | 44 | import java.util.Arrays; |
45 | 45 | import java.util.List; |
46 | 46 | import java.util.Optional; |
| 47 | +import java.util.concurrent.TimeUnit; |
47 | 48 |
|
48 | 49 | import javax.inject.Inject; |
49 | 50 |
|
@@ -178,7 +179,11 @@ public void execute(BuildFinishedFlowAction.Parameters parameters) throws FileNo |
178 | 179 | try { |
179 | 180 | // we are very generious here, as the upload can take |
180 | 181 | // a long time depending on its size |
181 | | - pb.start().waitFor(30, java.util.concurrent.TimeUnit.MINUTES); |
| 182 | + long timeoutSec = calculateUploadWaitTimeoutSeconds(uploadFile); |
| 183 | + boolean completedInTime = pb.start().waitFor(timeoutSec, TimeUnit.SECONDS); |
| 184 | + if (completedInTime == false) { |
| 185 | + System.out.println("Timed out waiting for buildkite artifact upload after " + timeoutSec + " seconds"); |
| 186 | + } |
182 | 187 | } catch (InterruptedException e) { |
183 | 188 | System.out.println("Failed to upload buildkite artifact " + e.getMessage()); |
184 | 189 | } |
@@ -278,5 +283,14 @@ private static void createBuildArchiveTar(List<File> files, File projectDir, Fil |
278 | 283 | private static String calculateArchivePath(Path path, Path projectPath) { |
279 | 284 | return path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString(); |
280 | 285 | } |
| 286 | + |
| 287 | + private static long calculateUploadWaitTimeoutSeconds(File file) { |
| 288 | + long fileSizeBytes = file.length(); |
| 289 | + long fileSizeMB = fileSizeBytes / (1024 * 1024); |
| 290 | + |
| 291 | + // Allocate 4 seconds per MB (assumes ~250 KB/s upload speed) |
| 292 | + // with min 10 seconds and max 30 minutes |
| 293 | + return Math.max(10, Math.min(1800, fileSizeMB * 4)); |
| 294 | + } |
281 | 295 | } |
282 | 296 | } |
0 commit comments