Skip to content

Commit

Permalink
throw meaningfull exception when download is interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 30, 2023
1 parent 450c8b8 commit 4f09be8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ public static String downloadModel(ModelDescriptor descriptor, String modelsDire
}
});
trackerThread.start();
DownloadTracker.printProgress(downloadThread, consumer);
try { DownloadTracker.printProgress(downloadThread, consumer); }
catch (InterruptedException ex) { throw new InterruptedException("Model download interrupted."); }

List<String> badDownloads = mdt.findMissingDownloads();

if (badDownloads.size() > 0 && Thread.currentThread().isAlive())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void downloadFileFromInternet(String downloadURL, File targetFile) {
new IOException(msg, e).printStackTrace();
} catch (InterruptedException e) {
consumer.accept(DOWNLOAD_ERROR_STR);
System.out.println("Download interrupted: " + downloadURL);
System.out.println("Download interrupted at file: " + downloadURL);
} finally {
try {
if (fos != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,10 @@ public static TwoParameterConsumer<String, Double> createConsumerProgress() {
* too
* @param consumer
* consumer that provides the info about the download
* @throws InterruptedException if the download is interrupted
*/
public static void printProgress(Thread downloadThread,
DownloadTracker.TwoParameterConsumer<String, Double> consumer) {
DownloadTracker.TwoParameterConsumer<String, Double> consumer) throws InterruptedException {
int n = 30;
String ogProgressStr = "";
String ogRemainingStr = "";
Expand All @@ -501,7 +502,8 @@ public static void printProgress(Thread downloadThread,
&& consumer.get().get(TOTAL_PROGRESS_KEY) == 1.0;
int millis = keep == true || end ? 10 : 3000;
keep = false;
try {Thread.sleep(millis);} catch (InterruptedException ex) {System.out.println("Stopping..."); break;}
//try {Thread.sleep(millis);} catch (InterruptedException ex) {System.out.println("Stopping..."); break;}
Thread.sleep(millis);
String select = null;
for (String key : consumer.get().keySet()) {
if (!already.contains(key) && !key.equals(DownloadTracker.TOTAL_PROGRESS_KEY)) {
Expand Down

0 comments on commit 4f09be8

Please sign in to comment.