Cancel any non repeating tasks when they exit

This commit is contained in:
Aurora Lahtela 2022-05-26 07:46:20 +03:00
parent 56081f0dc0
commit f3a5e27d8d
8 changed files with 67 additions and 28 deletions

View File

@ -62,7 +62,7 @@ subprojects {
ext {
daggerVersion = "2.42"
palVersion = "5.0.2"
palVersion = "5.0.3"
bukkitVersion = "1.13.2-R0.1-SNAPSHOT"
spigotVersion = "1.13.2-R0.1-SNAPSHOT"

View File

@ -57,23 +57,34 @@ public class ResourceWriteTask extends TaskSystem.Task {
@Override
public void run() {
try {
runTask();
} finally {
cancel();
}
}
private void runTask() {
ResourceService resourceService = ResourceService.getInstance();
Optional<ConfigNode> planCustomizationNode = getPlanCustomizationNode();
if (planCustomizationNode.isPresent()) {
for (ConfigNode child : planCustomizationNode.get().getChildren()) {
getPlanCustomizationNode().ifPresent(customizationNode -> {
for (ConfigNode child : customizationNode.getChildren()) {
if (child.getBoolean()) {
String resource = child.getKey(false).replace(',', '.');
try {
resourceService.getResource("Plan", resource, () -> files.getResourceFromJar("web/" + resource).asWebResource());
} catch (UncheckedIOException resourceNoLongerFound) {
if (!(resourceNoLongerFound.getCause() instanceof FileNotFoundException)) {
errorLogger.error(resourceNoLongerFound, ErrorContext.builder()
.whatToDo("A resource could not be read from the jar: " + resource + ", try restarting the server. Report this if error still occurs afterwards: " + resourceNoLongerFound.getMessage())
.build());
}
}
writeResource(resourceService, resource);
}
}
});
}
private void writeResource(ResourceService resourceService, String resource) {
try {
resourceService.getResource("Plan", resource, () -> files.getResourceFromJar("web/" + resource).asWebResource());
} catch (UncheckedIOException resourceNoLongerFound) {
if (!(resourceNoLongerFound.getCause() instanceof FileNotFoundException)) {
errorLogger.error(resourceNoLongerFound, ErrorContext.builder()
.whatToDo("A resource could not be read from the jar: " + resource + ", try restarting the server. Report this if error still occurs afterwards: " + resourceNoLongerFound.getMessage())
.build());
}
}
}

View File

@ -67,6 +67,14 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task {
@Override
public void run() {
try {
runTask();
} finally {
cancel();
}
}
private void runTask() {
Optional<ConfigNode> planCustomizationNode = getPlanCustomizationNode();
if (planCustomizationNode.isPresent()) {
try {
@ -104,14 +112,12 @@ public class WebAssetVersionCheckTask extends TaskSystem.Task {
private Optional<AssetInfo> findOutdatedResource(String resource) {
Optional<File> resourceFile = files.attemptToFind(resource);
Optional<Long> webAssetVersion = webAssetVersions.getWebAssetVersion(resource);
if (resourceFile.isPresent() && webAssetVersion.isPresent()) {
if (webAssetVersion.get() > resourceFile.get().lastModified()) {
return Optional.of(new AssetInfo(
resource,
resourceFile.get().lastModified(),
webAssetVersion.get()
));
}
if (resourceFile.isPresent() && webAssetVersion.isPresent() && webAssetVersion.get() > resourceFile.get().lastModified()) {
return Optional.of(new AssetInfo(
resource,
resourceFile.get().lastModified(),
webAssetVersion.get()
));
}
return Optional.empty();
}

View File

@ -103,7 +103,11 @@ public class ShutdownDataPreservation extends TaskSystem.Task {
@Override
public void run() {
storePreviouslyPreservedSessions();
try {
storePreviouslyPreservedSessions();
} finally {
cancel();
}
}
@Override

View File

@ -95,7 +95,11 @@ public class ShutdownHook extends Thread {
@Override
public void run() {
shutdownHook.register();
try {
shutdownHook.register();
} finally {
cancel();
}
}
@Override

View File

@ -58,9 +58,12 @@ public class ConfigStoreTask extends TaskSystem.Task {
@Override
public void run() {
long lastModified = files.getConfigFile().lastModified();
dbSystem.getDatabase().executeTransaction(new StoreConfigTransaction(serverInfo.getServerUUID(), config, lastModified));
cancel();
try {
long lastModified = files.getConfigFile().lastModified();
dbSystem.getDatabase().executeTransaction(new StoreConfigTransaction(serverInfo.getServerUUID(), config, lastModified));
} finally {
cancel();
}
}
@Override

View File

@ -51,8 +51,11 @@ public class NetworkConfigStoreTask extends TaskSystem.Task {
@Override
public void run() {
updateDBConfigs();
cancel();
try {
updateDBConfigs();
} finally {
cancel();
}
}
@Override

View File

@ -58,6 +58,14 @@ public class OldDependencyCacheDeletionTask extends TaskSystem.Task {
@Override
public void run() {
try {
runTask();
} finally {
cancel();
}
}
private void runTask() {
tryToDeleteDirectory(oldDependencyCache);
tryToDeleteDirectory(dependencyCache);