Skip to content

Commit

Permalink
Merge pull request #16 from Ferlab-Ste-Justine/fix/1085-reviews
Browse files Browse the repository at this point in the history
fix: CLIN-1085 - ignore failed compute size
  • Loading branch information
creativeyann17 authored Jun 14, 2022
2 parents 5f94405 + ca74f87 commit a28847a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Retrieve Ferload download link(s) ✅
Compute total average expected download size ✅
The total expected average download size will be 4 GB do you agree ? [yes]:
The total average expected download size will be 4GB do you want to continue (your available disk space is: 87 GB) ? [yes]
FIL0000010 [##################################################] 0 / 0 MB (100%) 📦
FIL0000002 [##################################################] 125 / 125 MB (100%) 📦
Expand All @@ -138,6 +138,13 @@ FIL0000006 [##################################################] 150 / 150
Total downloaded files: 12 located here: ./data
```

*Note: in case the tool can't compute the total average expected download size, the following message will be displayed:*
```
Failed to compute total average expected download size, reason: Future timed out after [60 seconds]
You can still proceed with the download, verify you have remaining disk-space available. ✅
```

# Technical

## Manifest file
Expand Down
18 changes: 15 additions & 3 deletions src/main/scala/ca/ferlab/ferload/client/commands/Download.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,29 @@ class Download(userConfig: UserConfig,
}

val totalExpectedDownloadSize = CommandBlock("Compute total average expected download size", successEmoji, padding) {
s3.getTotalExpectedDownloadSize(links, appConfig.getLong("size-estimation-timeout"))
Try(s3.getTotalExpectedDownloadSize(links, appConfig.getLong("size-estimation-timeout"))) match {
case Success(size) => size
case Failure(e) => {
println()
println()
println(s"Failed to compute total average expected download size, reason: ${e.getMessage}")
print(s"You can still proceed with the download, verify you have remaining disk-space available.")
0L
}
}
}

val totalExpectedDownloadSizeStr = if(totalExpectedDownloadSize > 0) FileUtils.byteCountToDisplaySize(totalExpectedDownloadSize) else "-"
val usableSpace = s3.getTotalAvailableDiskSpaceAt(outputDir)
val usableSPaceStr = FileUtils.byteCountToDisplaySize(usableSpace)

val downloadAgreement = appConfig.getString("download-agreement")
val agreedToDownload = commandLine.readLine(s"The total average expected download size will be " +
s"${FileUtils.byteCountToDisplaySize(totalExpectedDownloadSize)} do you want to continue ? [$downloadAgreement]")
s"$totalExpectedDownloadSizeStr do you want to continue (your available disk space is: $usableSPaceStr) ? [$downloadAgreement]")
println()

if (agreedToDownload.equals(downloadAgreement) || StringUtils.isBlank(agreedToDownload)) {

val usableSpace = s3.getTotalAvailableDiskSpaceAt(outputDir)
if (usableSpace < totalExpectedDownloadSize) {
throw new IllegalStateException(s"Not enough disk space available $usableSpace < $totalExpectedDownloadSize")
}
Expand Down

0 comments on commit a28847a

Please sign in to comment.