Commit 6e5603eb authored by Evgeni Sladkovskii's avatar Evgeni Sladkovskii

added sync call to run and result message

parent b9925cce
......@@ -13,14 +13,14 @@ import static nl.trifork.axondbbackupclient.util.FileUtils.ensureDir;
public class BackupService {
private final ControlDBBackupService controlDb;
private final SnapshotsBackupService segments;
private final SnapshotsBackupService snapshots;
private final EventsBackupService events;
private final BackupConfig config;
public void run(BackupJob job) {
ensureDirs(job);
controlDb.backup(job);
segments.backup(job);
snapshots.backup(job);
events.backup(job);
}
......
......@@ -57,7 +57,7 @@ public class EventsBackupService {
.filter(f -> closed.contains(f.getName()))
.collect(toList());
} catch (IOException e) {
log.error("Failed to read events dir", e);
log.error("Failed to read events dir");
throw new RuntimeException(e);
}
}
......@@ -77,7 +77,7 @@ public class EventsBackupService {
.filter(f -> !closed.contains(f))
.collect(toList());
} catch (IOException e) {
log.error("Failed to read events dir", e);
log.error("Failed to read events dir");
throw new RuntimeException(e);
}
}
......
......@@ -56,7 +56,7 @@ public class SnapshotsBackupService {
.filter(f -> closed.contains(f.getName()))
.collect(toList());
} catch (IOException e) {
log.error("Failed to read events dir", e);
log.error("Failed to read events dir");
throw new RuntimeException(e);
}
}
......@@ -76,7 +76,7 @@ public class SnapshotsBackupService {
.filter(f -> !closedSnapshots.contains(f))
.collect(toList());
} catch (IOException e) {
log.error("Failed to read snapshots dir", e);
log.error("Failed to read snapshots dir");
throw new RuntimeException(e);
}
}
......
......@@ -12,6 +12,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import static nl.trifork.axondbbackupclient.cron.BackupStatus.DONE;
import static nl.trifork.axondbbackupclient.cron.BackupStatus.ERROR;
import static nl.trifork.axondbbackupclient.cron.BackupStatus.SCHEDULLED;
@Data
......@@ -47,4 +49,8 @@ public class BackupTask {
return status.values().stream().allMatch(BackupStatus::isFinished);
}
public BackupStatus finishResult() {
return status.values().stream().allMatch(s -> s == DONE) ? DONE : ERROR;
}
}
......@@ -19,11 +19,16 @@ public class Controller {
private final BackupConfig config;
@PostMapping("/run")
public String runBackup() {
public String runBackup() throws InterruptedException {
BackupTask task = task(config.getJobs());
log.info("Adding task {}", task);
runner.add(task);
return "Submitted";
while (!task.isFinished()) {
Thread.sleep(100);
}
return task.finishResult().name();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment