1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-01 19:40:18 +02:00

Move the sleep function to Utils

This commit is contained in:
Zsombor Gegesy
2022-08-04 08:12:19 +02:00
committed by soloturn
parent e6ccfc0a34
commit b72a49f6f6
3 changed files with 13 additions and 12 deletions

View File

@@ -39,6 +39,7 @@ class DownloadFileThread extends Thread {
private final int TIMEOUT; private final int TIMEOUT;
private final int retrySleep;
public DownloadFileThread(URL url, File saveAs, AbstractRipper observer, Boolean getFileExtFromMIME) { public DownloadFileThread(URL url, File saveAs, AbstractRipper observer, Boolean getFileExtFromMIME) {
super(); super();
this.url = url; this.url = url;
@@ -47,6 +48,7 @@ class DownloadFileThread extends Thread {
this.observer = observer; this.observer = observer;
this.retries = Utils.getConfigInteger("download.retries", 1); this.retries = Utils.getConfigInteger("download.retries", 1);
this.TIMEOUT = Utils.getConfigInteger("download.timeout", 60000); this.TIMEOUT = Utils.getConfigInteger("download.timeout", 60000);
this.retrySleep = Utils.getConfigInteger("download.retry.sleep", 0);
this.getFileExtFromMIME = getFileExtFromMIME; this.getFileExtFromMIME = getFileExtFromMIME;
} }
@@ -62,6 +64,7 @@ class DownloadFileThread extends Thread {
* Attempts to download the file. Retries as needed. Notifies observers upon * Attempts to download the file. Retries as needed. Notifies observers upon
* completion/error/warn. * completion/error/warn.
*/ */
@Override
public void run() { public void run() {
// First thing we make sure the file name doesn't have any illegal chars in it // First thing we make sure the file name doesn't have any illegal chars in it
saveAs = new File( saveAs = new File(
@@ -300,13 +303,8 @@ class DownloadFileThread extends Thread {
Utils.getLocalizedString("failed.to.download") + " " + url.toExternalForm()); Utils.getLocalizedString("failed.to.download") + " " + url.toExternalForm());
return; return;
} else { } else {
final var retrySleep = Utils.getConfigInteger("download.retry.sleep", 0);
if (retrySleep > 0) { if (retrySleep > 0) {
try { Utils.sleep(retrySleep);
sleep(retrySleep);
} catch (final InterruptedException e) {
e.printStackTrace();
}
} }
} }
} while (true); } while (true);

View File

@@ -218,12 +218,8 @@ public class Http {
} }
if (retrySleep > 0 && retries >= 0) { if (retrySleep > 0 && retries >= 0) {
try { logger.warn("Error while loading " + url + " waiting "+ retrySleep + " ms before retrying.", e);
logger.warn("Error while loading " + url + " waiting "+ retrySleep + " ms before retrying.", e); Utils.sleep(retrySleep);
Thread.sleep(retrySleep);
} catch (final InterruptedException e1) {
e1.printStackTrace();
}
} else { } else {
logger.warn("Error while loading " + url, e); logger.warn("Error while loading " + url, e);
} }

View File

@@ -866,4 +866,11 @@ public class Utils {
return Paths.get(fullPath); return Paths.get(fullPath);
} }
public static void sleep(long time) {
try {
Thread.sleep(time);
} catch (final InterruptedException e1) {
e1.printStackTrace();
}
}
} }