Fix up server timeout code

This commit is contained in:
Colin McDonald 2016-07-14 21:51:48 -04:00
parent 210938644a
commit 3ea54fdfcd

View File

@ -11,6 +11,7 @@ import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies; import net.frozenorb.apiv3.serialization.gson.ExcludeFromReplies;
import net.frozenorb.apiv3.unsorted.MongoToVoidMongoCallback; import net.frozenorb.apiv3.unsorted.MongoToVoidMongoCallback;
import net.frozenorb.apiv3.util.SyncUtils; import net.frozenorb.apiv3.util.SyncUtils;
import net.frozenorb.apiv3.util.TimeUtils;
import org.bson.Document; import org.bson.Document;
import java.time.Instant; import java.time.Instant;
@ -64,27 +65,25 @@ public final class Server {
})); }));
} }
// TODO: This code isn't multi-instance safe AND will send more
// db requests than needed.
private static void updateTimedOutServers() { private static void updateTimedOutServers() {
/*for (Server server : serverCache) { for (Server server : serverCache) {
int lastUpdatedAgo = TimeUtils.getSecondsBetween(server.getLastUpdatedAt(), Instant.now()); int lastUpdatedAgo = TimeUtils.getSecondsBetween(server.getLastUpdatedAt(), Instant.now());
if (lastUpdatedAgo < TimeUnit.SECONDS.toSeconds(30)) { if (lastUpdatedAgo < 60 || lastUpdatedAgo > 30 * 5) {
return; return;
} }
for (UUID online : server.getPlayers()) { for (UUID online : server.getPlayers()) {
User.findById(online, (user, error) -> { User.findById(online, (user, findUserError) -> {
if (error != null) { if (findUserError != null) {
error.printStackTrace(); findUserError.printStackTrace();
return; return;
} }
if (user.leftServer(server)) { if (user.leftServer(server)) {
user.save((ignored, error2) -> { user.save((ignored, saveUserError) -> {
if (error2 != null) { if (saveUserError != null) {
error2.printStackTrace(); saveUserError.printStackTrace();
} }
}); });
} }
@ -97,7 +96,7 @@ public final class Server {
error.printStackTrace(); error.printStackTrace();
} }
}); });
}*/ }
} }
private Server() {} // For Jackson private Server() {} // For Jackson