Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

Commit

Permalink
Make Redis Layer save on shutdown for profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahseguin committed Aug 23, 2019
1 parent f1928b7 commit c3465b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jonahseguin.payload.profile.layers;

import com.jonahseguin.payload.Payload;
import com.jonahseguin.payload.common.cache.CacheDatabase;
import com.jonahseguin.payload.common.exception.CachingException;
import com.jonahseguin.payload.common.exception.PayloadException;
Expand All @@ -12,6 +13,9 @@
import com.jonahseguin.payload.profile.type.PCacheStage;
import com.mongodb.BasicDBObject;
import com.mongodb.util.JSONParseException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.exceptions.JedisException;

Expand Down Expand Up @@ -124,6 +128,25 @@ public boolean init() {

@Override
public boolean shutdown() {
int errors = 0;
for (Player player : Bukkit.getOnlinePlayers()) {
T profile = getCache().getLocalProfile(player); // Get locally only
if (profile != null) {
// Save only here (Redis)
if (!this.save(profile)) {
player.sendMessage(ChatColor.RED + "Failed to save your profile during shutdown. Please notify an administrator of this error. [Redis]");
debug(Payload.format("&c{0}'s profile failed to save during shutdown. (FATAL ERROR: potential data loss) [Redis]"));
errors++;
}
} else {
// Player is online without a loaded PayloadProfile... this should not happen
player.sendMessage(ChatColor.RED + "You do not appear to have a loaded profile. Please notify an administrator of this error. [Redis]");
debug(Payload.format("&c{0} is online without a loaded profile. This should not happen. (shutdown) [Redis] ", player.getName()));
errors++;
}
}
debug(ChatColor.RED + "[FATAL ERROR] There were " + errors + " errors during MongoDB shutdown involving profile saving. [Redis]");

try {
if (jedis != null) {
jedis.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public final boolean init() {

public final boolean shutdown() {
boolean success = true;
if (!mongoLayer.shutdown()) {
if (!redisLayer.shutdown()) {
success = false;
}
if (!redisLayer.shutdown()) {
if (!mongoLayer.shutdown()) {
success = false;
}
if (!preCachingLayer.shutdown()) {
Expand Down

0 comments on commit c3465b2

Please sign in to comment.