Fixed db error on reload when export is running

This commit is contained in:
Rsl1122 2019-09-30 14:31:22 +03:00
parent 756851fcc2
commit 56dae4c829
6 changed files with 53 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.exceptions.database.DBOpException;
import com.djrapitops.plan.utilities.java.ThrowingConsumer;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
@ -48,10 +49,22 @@ public class ExportTask extends AbsRunnable {
exportAction.accept(exporter);
} catch (ExportException e) {
errorHandler.log(L.WARN, this.getClass(), e);
} catch (DBOpException dbException) {
handleDBException(dbException);
} catch (Exception | NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
logger.error("Export Task Disabled due to error, reload Plan to re-enable.");
errorHandler.log(L.ERROR, this.getClass(), e);
cancel();
}
}
private void handleDBException(DBOpException dbException) {
logger.error("Export Task Disabled due to database error, reload Plan to re-enable.");
if (dbException.getMessage().contains("closed")) {
logger.warn("(Error was caused by database closing, so this error can possibly be ignored.)");
} else {
errorHandler.log(L.ERROR, this.getClass(), dbException);
}
cancel();
}
}

View File

@ -28,6 +28,8 @@ import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
@ -47,6 +49,7 @@ import java.nio.file.Path;
public class NetworkPageExporter extends FileExporter {
private final PlanFiles files;
private final DBSystem dbSystem;
private final PageFactory pageFactory;
private final RootJSONHandler jsonHandler;
private final Locale locale;
@ -57,12 +60,14 @@ public class NetworkPageExporter extends FileExporter {
@Inject
public NetworkPageExporter(
PlanFiles files,
DBSystem dbSystem,
PageFactory pageFactory,
RootJSONHandler jsonHandler,
Locale locale,
Theme theme
) {
this.files = files;
this.dbSystem = dbSystem;
this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler;
this.locale = locale;
@ -72,6 +77,9 @@ public class NetworkPageExporter extends FileExporter {
}
public void export(Path toDirectory, Server server) throws IOException, NotFoundException, ParseException {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
exportPaths.put("./players", toRelativePathFromRoot("players"));
exportRequiredResources(toDirectory);
exportJSON(toDirectory, server);

View File

@ -17,6 +17,8 @@
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.webserver.response.ResponseFactory;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -32,16 +34,22 @@ import java.util.UUID;
@Singleton
public class PlayerJSONExporter extends FileExporter {
private final DBSystem dbSystem;
private final ResponseFactory responseFactory;
@Inject
public PlayerJSONExporter(
DBSystem dbSystem,
ResponseFactory responseFactory
) {
this.dbSystem = dbSystem;
this.responseFactory = responseFactory;
}
public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
Path to = toDirectory.resolve("player/" + toFileName(playerName) + ".json");
exportJSON(to, playerUUID);
}

View File

@ -27,6 +27,8 @@ import com.djrapitops.plan.exceptions.connection.NotFoundException;
import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
@ -47,6 +49,7 @@ import java.util.UUID;
public class PlayerPageExporter extends FileExporter {
private final PlanFiles files;
private final DBSystem dbSystem;
private final PageFactory pageFactory;
private final RootJSONHandler jsonHandler;
private final Locale locale;
@ -57,12 +60,14 @@ public class PlayerPageExporter extends FileExporter {
@Inject
public PlayerPageExporter(
PlanFiles files,
DBSystem dbSystem,
PageFactory pageFactory,
RootJSONHandler jsonHandler,
Locale locale,
Theme theme
) {
this.files = files;
this.dbSystem = dbSystem;
this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler;
this.locale = locale;
@ -72,6 +77,9 @@ public class PlayerPageExporter extends FileExporter {
}
public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException, ParseException {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
exportPaths.put("../network", toRelativePathFromRoot("network"));
exportPaths.put("../server", toRelativePathFromRoot("server"));
exportRequiredResources(toDirectory);

View File

@ -28,6 +28,8 @@ import com.djrapitops.plan.exceptions.connection.WebException;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
@ -47,6 +49,7 @@ import java.nio.file.Path;
public class PlayersPageExporter extends FileExporter {
private final PlanFiles files;
private final DBSystem dbSystem;
private final PageFactory pageFactory;
private final RootJSONHandler jsonHandler;
private final Locale locale;
@ -58,6 +61,7 @@ public class PlayersPageExporter extends FileExporter {
@Inject
public PlayersPageExporter(
PlanFiles files,
DBSystem dbSystem,
PageFactory pageFactory,
RootJSONHandler jsonHandler,
Locale locale,
@ -65,6 +69,7 @@ public class PlayersPageExporter extends FileExporter {
ServerInfo serverInfo
) {
this.files = files;
this.dbSystem = dbSystem;
this.pageFactory = pageFactory;
this.jsonHandler = jsonHandler;
this.locale = locale;
@ -75,6 +80,9 @@ public class PlayersPageExporter extends FileExporter {
}
public void export(Path toDirectory) throws IOException, NotFoundException, ParseException {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
exportPaths.put("/", toRelativePathFromRoot(serverInfo.getServer().isProxy() ? "network" : "server"));
exportRequiredResources(toDirectory);
exportJSON(toDirectory);

View File

@ -29,6 +29,8 @@ import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.file.PlanFiles;
import com.djrapitops.plan.storage.file.Resource;
import org.apache.commons.lang3.StringUtils;
@ -50,6 +52,7 @@ public class ServerPageExporter extends FileExporter {
private final PlanFiles files;
private final PageFactory pageFactory;
private final DBSystem dbSystem;
private final RootJSONHandler jsonHandler;
private final Locale locale;
private final Theme theme;
@ -61,6 +64,7 @@ public class ServerPageExporter extends FileExporter {
public ServerPageExporter(
PlanFiles files,
PageFactory pageFactory,
DBSystem dbSystem,
RootJSONHandler jsonHandler,
Locale locale,
Theme theme,
@ -68,6 +72,7 @@ public class ServerPageExporter extends FileExporter {
) {
this.files = files;
this.pageFactory = pageFactory;
this.dbSystem = dbSystem;
this.jsonHandler = jsonHandler;
this.locale = locale;
this.theme = theme;
@ -77,6 +82,9 @@ public class ServerPageExporter extends FileExporter {
}
public void export(Path toDirectory, Server server) throws IOException, NotFoundException, ParseException {
Database.State dbState = dbSystem.getDatabase().getState();
if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return;
exportPaths.put("../network", toRelativePathFromRoot("network"));
exportRequiredResources(toDirectory);
exportJSON(toDirectory, server);