Make sure that the faster online check for offline Chaturbate models works as intended
This commit is contained in:
parent
f6e02b4a35
commit
aa44917935
|
@ -6,6 +6,7 @@ import ctbrec.event.EventBusHolder;
|
||||||
import ctbrec.event.ModelIsOnlineEvent;
|
import ctbrec.event.ModelIsOnlineEvent;
|
||||||
import ctbrec.event.ModelStateChangedEvent;
|
import ctbrec.event.ModelStateChangedEvent;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
|
import ctbrec.sites.chaturbate.ChaturbateModel;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
import static ctbrec.Model.State.OFFLINE;
|
||||||
import static ctbrec.Model.State.UNKNOWN;
|
import static ctbrec.Model.State.UNKNOWN;
|
||||||
|
|
||||||
public class OnlineMonitor extends Thread {
|
public class OnlineMonitor extends Thread {
|
||||||
|
@ -112,7 +114,12 @@ public class OnlineMonitor extends Thread {
|
||||||
EventBusHolder.BUS.post(new ModelIsOnlineEvent(model));
|
EventBusHolder.BUS.post(new ModelIsOnlineEvent(model));
|
||||||
model.setLastSeen(Instant.now());
|
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);
|
LOG.debug("Model online state: {} {}", model.getName(), state);
|
||||||
Model.State oldState = states.getOrDefault(model, UNKNOWN);
|
Model.State oldState = states.getOrDefault(model, UNKNOWN);
|
||||||
states.put(model, state);
|
states.put(model, state);
|
||||||
|
|
|
@ -62,8 +62,8 @@ public class ChaturbateModel extends AbstractModel {
|
||||||
log.trace("Model {} offline", getName());
|
log.trace("Model {} offline", getName());
|
||||||
} else {
|
} else {
|
||||||
StreamInfo info = getStreamInfo();
|
StreamInfo info = getStreamInfo();
|
||||||
roomStatus = Optional.ofNullable(info).map(i -> i.room_status).orElse("");
|
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"));
|
log.trace("Model {} room status: {}", getName(), Optional.ofNullable(info).map(i -> i.room_status).orElse("Unknown"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StreamInfo info = getStreamInfo(true);
|
StreamInfo info = getStreamInfo(true);
|
||||||
|
@ -143,7 +143,11 @@ public class ChaturbateModel extends AbstractModel {
|
||||||
@Override
|
@Override
|
||||||
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||||
if (failFast) {
|
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 {
|
} else {
|
||||||
if (isOffline()) {
|
if (isOffline()) {
|
||||||
onlineState = OFFLINE;
|
onlineState = OFFLINE;
|
||||||
|
@ -303,7 +307,7 @@ public class ChaturbateModel extends AbstractModel {
|
||||||
lastStreamInfoRequest = Instant.now();
|
lastStreamInfoRequest = Instant.now();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String content = response.body().string();
|
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);
|
streamInfo = mapper.readValue(content, StreamInfo.class);
|
||||||
return streamInfo;
|
return streamInfo;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue