Encapsulate message_state.maybe_restart_event_loop().

We now set the timer for missing events inside the
message_state class, where it's easier for us to know
which state we're in.
This commit is contained in:
Steve Howell
2017-07-13 14:24:06 -04:00
committed by showell
parent bc67f6a8ca
commit fe66d4f3b0
2 changed files with 22 additions and 12 deletions

View File

@@ -239,9 +239,6 @@ exports.transmit_message = function (request, on_success, error) {
// Once everything is done, get ready to report times to the server.
message_state.process_success();
// TODO: rework the timers
sent_messages.set_timer_for_restarting_event_loop(client_message_id);
}
if (page_params.use_websockets) {

View File

@@ -71,6 +71,19 @@ exports.message_state = function (opts) {
self.data.send_finished = undefined;
self.data.rendered_content_disparity = false;
self.maybe_restart_event_loop = function () {
if (self.data.received) {
// We got our event, no need to do anything
return;
}
blueslip.log("Restarting get_events due to " +
"delayed receipt of sent message " +
self.data.client_message_id);
server_events.restart_get_events();
};
self.maybe_report_send_times = function () {
if (!self.ready()) {
return;
@@ -100,6 +113,15 @@ exports.message_state = function (opts) {
self.process_success = function () {
var send_finished = new Date();
// We only start our timer for events coming in here,
// since it's plausible the server rejected our message,
// or took a while to process it, but there is nothing
// wrong with our event loop.
if (!self.data.received) {
setTimeout(self.maybe_restart_event_loop, 5000);
}
var send_time = (send_finished - self.data.start);
if (feature_flags.log_send_times) {
blueslip.log("send time: " + send_time);
@@ -169,15 +191,6 @@ exports.report_as_received = function report_as_received(client_message_id) {
}
};
exports.set_timer_for_restarting_event_loop = function (client_message_id) {
setTimeout(function () {
if (!exports.send_times_data[client_message_id].was_received()) {
blueslip.log("Restarting get_events due to delayed receipt of sent message " + client_message_id);
server_events.restart_get_events();
}
}, 5000);
};
exports.initialize = function () {
exports.reset_id_state();
};