use ChronoUnit instead of TimeUnit
This commit is contained in:
parent
626bb3e25a
commit
c6eb4c8fdb
|
@ -11,6 +11,7 @@ import org.tomlj.TomlArray;
|
|||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -63,8 +64,10 @@ public class TaskBuilder {
|
|||
File outputFile = new File(backupDir, fileName);
|
||||
|
||||
if (doVAC) {
|
||||
TimeUnit unit =
|
||||
TimeUnit.valueOf(getTaskConfig().getStringOrDefault("vacuum.unit", TimeUnit.DAYS.name()));
|
||||
ChronoUnit unit =
|
||||
ChronoUnit.valueOf(
|
||||
getTaskConfig().getStringOrDefault("vacuum.unit", ChronoUnit.DAYS.name()));
|
||||
|
||||
int value = getTaskConfig().getIntOrDefault("vacuum.time", 5);
|
||||
|
||||
System.out.printf("Adding VacuumTask with lifetime of %d %s%n", value, unit.name());
|
||||
|
|
|
@ -4,18 +4,19 @@ import lombok.Getter;
|
|||
import net.horizoncode.sysbackup.tasks.Task;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Getter
|
||||
public class VacuumTask extends Task {
|
||||
|
||||
private final File backupDir;
|
||||
private final TimeUnit unit;
|
||||
private final ChronoUnit unit;
|
||||
private final int value;
|
||||
|
||||
public VacuumTask(File backupDir, TimeUnit unit, int value) {
|
||||
public VacuumTask(File backupDir, ChronoUnit unit, int value) {
|
||||
this.backupDir = backupDir;
|
||||
this.unit = unit;
|
||||
this.value = value;
|
||||
|
@ -25,7 +26,10 @@ public class VacuumTask extends Task {
|
|||
public void start() {
|
||||
if (backupDir.listFiles() != null) {
|
||||
Arrays.stream(Objects.requireNonNull(backupDir.listFiles()))
|
||||
.filter(file -> file.lastModified() + unit.toMillis(value) <= System.currentTimeMillis())
|
||||
.filter(
|
||||
file ->
|
||||
file.lastModified() + Duration.of(value, unit).toMillis()
|
||||
<= System.currentTimeMillis())
|
||||
.forEachOrdered(File::deleteOnExit);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ outputFile = "{date} - {taskName}"
|
|||
[vacuum]
|
||||
enabled = true
|
||||
time = 5
|
||||
unit = "DAYS" # See java.util.concurrent.TimeUnit
|
||||
unit = "DAYS" # See java.time.temporal.ChronoUnit
|
||||
|
||||
[mysql]
|
||||
enabled = true
|
||||
|
|
Loading…
Reference in New Issue
Block a user