Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strengthen uploadthread #196

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions DriveBackup/src/main/java/ratismal/drivebackup/UploadThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.TreeMap;

import static ratismal.drivebackup.config.Localization.intl;
Expand Down Expand Up @@ -189,13 +187,32 @@ public void initiatorError(String input, String... placeholders) {
*/
@Override
public void run() {
Config config = ConfigParser.getConfig();
if (initiator != null && backupStatus != BackupStatus.NOT_RUNNING) {
logger.initiatorError(
intl("backup-already-running"),
intl("backup-already-running"),
"backup-status", getBackupStatus());
return;
}
try {
run_internal();
} catch (Exception e) {
lastBackupSuccessful = false;
throw e;
} finally {
backupStatus = BackupStatus.NOT_RUNNING;
if (lastBackupSuccessful) {
DriveBackupApi.backupDone();
} else {
DriveBackupApi.backupError();
}
}
}

/**
* actual backup logic
*/
void run_internal() {
Config config = ConfigParser.getConfig();
totalTimer.start();
backupStatus = BackupStatus.STARTING;
if (!locationsToBePruned.isEmpty()) {
Expand Down Expand Up @@ -304,12 +321,6 @@ public void run() {
long totalBackupTime = totalTimer.getTime();
long totalSeconds = Duration.of(totalBackupTime, ChronoUnit.MILLIS).getSeconds();
logger.log(intl("backup-total-time"), "time", String.valueOf(totalSeconds));
backupStatus = BackupStatus.NOT_RUNNING;
if (errorOccurred) {
DriveBackupApi.backupError();
} else {
DriveBackupApi.backupDone();
}
}

private void ensureMethodsAuthenticated() {
Expand Down Expand Up @@ -563,11 +574,9 @@ public static String getBackupStatus() {
message = intl("backup-status-uploading");
break;
case STARTING:
message = intl("backup-status-starting");
break;
return intl("backup-status-starting");
case PRUNING:
message = intl("backup-status-pruning");
break;
return intl("backup-status-pruning");
default:
return intl("backup-status-not-running");
}
Expand Down Expand Up @@ -604,7 +613,7 @@ public static String getNextAutoBackup() {
* Sets the time of the next interval-based backup to the current time + the configured interval.
*/
public static void updateNextIntervalBackupTime() {
nextIntervalBackupTime = LocalDateTime.now().plus(ConfigParser.getConfig().backupStorage.delay, ChronoUnit.MINUTES);
nextIntervalBackupTime = LocalDateTime.now().plusMinutes(ConfigParser.getConfig().backupStorage.delay);
}

public static boolean wasLastBackupSuccessful() {
Expand Down
Loading