forked from j62/ctbrec
Reduce config save spam from recorder operations (400ms delay)
This commit is contained in:
parent
994bb99b1f
commit
466d705131
|
@ -30,6 +30,7 @@ import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
|
|
||||||
import static ctbrec.Recording.State.WAITING;
|
import static ctbrec.Recording.State.WAITING;
|
||||||
|
@ -64,6 +65,9 @@ public class SimplifiedLocalRecorder implements Recorder {
|
||||||
private final Thread maintenanceThread;
|
private final Thread maintenanceThread;
|
||||||
private long lastSpaceCheck;
|
private long lastSpaceCheck;
|
||||||
|
|
||||||
|
Timer saveConfigTimer = new Timer();
|
||||||
|
TimerTask saveConfigTask = null;
|
||||||
|
|
||||||
|
|
||||||
public SimplifiedLocalRecorder(Config config, List<Site> sites) throws IOException {
|
public SimplifiedLocalRecorder(Config config, List<Site> sites) throws IOException {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
@ -553,16 +557,30 @@ public class SimplifiedLocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
||||||
} catch (IOException e) {
|
|
||||||
errorSavingConfig(e);
|
|
||||||
} finally {
|
} finally {
|
||||||
recorderLock.unlock();
|
recorderLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveConfig() throws IOException {
|
private void saveConfig() {
|
||||||
config.getSettings().models = models.stream().map(Mappers.getMapper(ModelMapper.class)::toDto).collect(Collectors.toList());
|
if (saveConfigTask != null)
|
||||||
config.save();
|
saveConfigTask.cancel();
|
||||||
|
|
||||||
|
saveConfigTask = new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
recorderLock.lock();
|
||||||
|
try {
|
||||||
|
config.getSettings().models = models.stream().map(Mappers.getMapper(ModelMapper.class)::toDto).collect(Collectors.toList());
|
||||||
|
config.save();
|
||||||
|
} catch (IOException e) {
|
||||||
|
errorSavingConfig(e);
|
||||||
|
} finally {
|
||||||
|
recorderLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
saveConfigTimer.schedule(saveConfigTask, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -622,8 +640,6 @@ public class SimplifiedLocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
||||||
} catch (IOException e) {
|
|
||||||
errorSavingConfig(e);
|
|
||||||
} finally {
|
} finally {
|
||||||
recorderLock.unlock();
|
recorderLock.unlock();
|
||||||
}
|
}
|
||||||
|
@ -901,8 +917,6 @@ public class SimplifiedLocalRecorder implements Recorder {
|
||||||
} else {
|
} else {
|
||||||
log.warn("Couldn't change priority for model {}. Not found in list", model.getName());
|
log.warn("Couldn't change priority for model {}. Not found in list", model.getName());
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
errorSavingConfig(e);
|
|
||||||
} finally {
|
} finally {
|
||||||
recorderLock.unlock();
|
recorderLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue