Make sure that the faster online check for offline Chaturbate models works as intended

This commit is contained in:
0xb00bface 2023-12-30 21:07:15 +01:00
parent f6e02b4a35
commit aa44917935
2 changed files with 16 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import ctbrec.event.EventBusHolder;
import ctbrec.event.ModelIsOnlineEvent;
import ctbrec.event.ModelStateChangedEvent;
import ctbrec.io.HttpException;
import ctbrec.sites.chaturbate.ChaturbateModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,6 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
import static ctbrec.Model.State.OFFLINE;
import static ctbrec.Model.State.UNKNOWN;
public class OnlineMonitor extends Thread {
@ -112,7 +114,12 @@ public class OnlineMonitor extends Thread {
EventBusHolder.BUS.post(new ModelIsOnlineEvent(model));
model.setLastSeen(Instant.now());
}
Model.State state = model.getOnlineState(false);
Model.State state;
if (model instanceof ChaturbateModel && model.getOnlineState(true) == OFFLINE) {
state = OFFLINE;
} else {
state = model.getOnlineState(false);
}
LOG.debug("Model online state: {} {}", model.getName(), state);
Model.State oldState = states.getOrDefault(model, UNKNOWN);
states.put(model, state);

View File

@ -62,8 +62,8 @@ public class ChaturbateModel extends AbstractModel {
log.trace("Model {} offline", getName());
} else {
StreamInfo info = getStreamInfo();
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
log.trace("Model {} room status: {}", getName(), Optional.ofNullable(info).map(i -> i.room_status).orElse("unknown"));
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("Unknown");
log.trace("Model {} room status: {}", getName(), Optional.ofNullable(info).map(i -> i.room_status).orElse("Unknown"));
}
} else {
StreamInfo info = getStreamInfo(true);
@ -143,7 +143,11 @@ public class ChaturbateModel extends AbstractModel {
@Override
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
if (failFast) {
setOnlineStateByRoomStatus(Optional.ofNullable(streamInfo).map(si -> si.room_status).orElse("Unknown"));
if (onlineState != UNKNOWN) {
return onlineState;
} else {
setOnlineStateByRoomStatus(Optional.ofNullable(streamInfo).map(si -> si.room_status).orElse("unknown"));
}
} else {
if (isOffline()) {
onlineState = OFFLINE;
@ -303,7 +307,7 @@ public class ChaturbateModel extends AbstractModel {
lastStreamInfoRequest = Instant.now();
if (response.isSuccessful()) {
String content = response.body().string();
log.trace("Raw stream info for model {}: {}", getName(), content);
log.debug("Raw stream info for model {}: {}", getName(), content);
streamInfo = mapper.readValue(content, StreamInfo.class);
return streamInfo;
} else {