forked from j62/ctbrec
1
0
Fork 0

Add setting for online check interval

This commit is contained in:
0xboobface 2018-11-25 17:04:49 +01:00
parent 9965f352e3
commit 240e5e0d92
2 changed files with 21 additions and 12 deletions

View File

@ -72,4 +72,5 @@ public class Settings {
public int windowY; public int windowY;
public int splitRecordings = 0; public int splitRecordings = 0;
public List<String> disabledSites = new ArrayList<>(); public List<String> disabledSites = new ArrayList<>();
public long onlineCheckIntervalInSecs = 60;
} }

View File

@ -9,6 +9,7 @@ import java.nio.file.Files;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -404,15 +405,14 @@ public class LocalRecorder implements Recorder {
public void run() { public void run() {
running = true; running = true;
while (running) { while (running) {
Instant begin = Instant.now();
for (Model model : getModelsRecording()) { for (Model model : getModelsRecording()) {
try { try {
if (!model.isSuspended() && !recordingProcesses.containsKey(model)) { boolean isOnline = model.isOnline(IGNORE_CACHE);
boolean isOnline = model.isOnline(IGNORE_CACHE); LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline"));
LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline")); if (isOnline && !isSuspended(model) && !recordingProcesses.containsKey(model)) {
if (isOnline) { LOG.info("Model {}'s room back to public. Starting recording", model);
LOG.info("Model {}'s room back to public. Starting recording", model); startRecordingProcess(model);
startRecordingProcess(model);
}
} }
} catch (HttpException e) { } catch (HttpException e) {
LOG.error("Couldn't check if model {} is online. HTTP Response: {} - {}", LOG.error("Couldn't check if model {} is online. HTTP Response: {} - {}",
@ -421,12 +421,20 @@ public class LocalRecorder implements Recorder {
LOG.error("Couldn't check if model {} is online", model.getName(), e); LOG.error("Couldn't check if model {} is online", model.getName(), e);
} }
} }
Instant end = Instant.now();
Duration timeCheckTook = Duration.between(begin, end);
try { long sleepTime = Config.getInstance().getSettings().onlineCheckIntervalInSecs;
if (running) if(timeCheckTook.getSeconds() < sleepTime) {
Thread.sleep(TimeUnit.SECONDS.toMillis(60)); try {
} catch (InterruptedException e) { if (running) {
LOG.trace("Sleep interrupted"); long millis = TimeUnit.SECONDS.toMillis(sleepTime - timeCheckTook.getSeconds());
LOG.trace("Sleeping {}ms", millis);
Thread.sleep(millis);
}
} catch (InterruptedException e) {
LOG.trace("Sleep interrupted");
}
} }
} }
LOG.debug(getName() + " terminated"); LOG.debug(getName() + " terminated");