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

View File

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

View File

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