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.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
import static ctbrec.Recording.State.WAITING;
|
||||
|
@ -64,6 +65,9 @@ public class SimplifiedLocalRecorder implements Recorder {
|
|||
private final Thread maintenanceThread;
|
||||
private long lastSpaceCheck;
|
||||
|
||||
Timer saveConfigTimer = new Timer();
|
||||
TimerTask saveConfigTask = null;
|
||||
|
||||
|
||||
public SimplifiedLocalRecorder(Config config, List<Site> sites) throws IOException {
|
||||
this.config = config;
|
||||
|
@ -553,16 +557,30 @@ public class SimplifiedLocalRecorder implements Recorder {
|
|||
}
|
||||
|
||||
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
||||
} catch (IOException e) {
|
||||
errorSavingConfig(e);
|
||||
} finally {
|
||||
recorderLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveConfig() throws IOException {
|
||||
config.getSettings().models = models.stream().map(Mappers.getMapper(ModelMapper.class)::toDto).collect(Collectors.toList());
|
||||
config.save();
|
||||
private void saveConfig() {
|
||||
if (saveConfigTask != null)
|
||||
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
|
||||
|
@ -622,8 +640,6 @@ public class SimplifiedLocalRecorder implements Recorder {
|
|||
}
|
||||
|
||||
getRecordingProcessForModel(model).ifPresent(this::stopRecordingProcess);
|
||||
} catch (IOException e) {
|
||||
errorSavingConfig(e);
|
||||
} finally {
|
||||
recorderLock.unlock();
|
||||
}
|
||||
|
@ -901,8 +917,6 @@ public class SimplifiedLocalRecorder implements Recorder {
|
|||
} else {
|
||||
log.warn("Couldn't change priority for model {}. Not found in list", model.getName());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
errorSavingConfig(e);
|
||||
} finally {
|
||||
recorderLock.unlock();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue