mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02:00
[Debt] Moved LogsFolderCleanTask out of PlanFiles
This had to be done in order for a call to settings to be made without a dependency cycle, since PlanConfig depends on PlanFiles.
This commit is contained in:
parent
b972c26fe8
commit
7f53fb4c80
|
@ -7,9 +7,7 @@ package com.djrapitops.plan.system.file;
|
|||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.tasks.LogsFolderCleanTask;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -17,7 +15,6 @@ import javax.inject.Singleton;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Abstracts File methods of Plugin classes so that they can be tested without Mocks.
|
||||
|
@ -43,7 +40,7 @@ public class PlanFiles implements SubSystem {
|
|||
return dataFolder;
|
||||
}
|
||||
|
||||
private File getLogsFolder() {
|
||||
public File getLogsFolder() {
|
||||
File folder = getFileFromPluginFolder("logs");
|
||||
folder.mkdirs();
|
||||
return folder;
|
||||
|
@ -68,12 +65,6 @@ public class PlanFiles implements SubSystem {
|
|||
try {
|
||||
Verify.isTrue((configFile.exists() && configFile.isFile()) || configFile.createNewFile(),
|
||||
() -> new EnableException("Could not create config file at " + configFile.getAbsolutePath()));
|
||||
|
||||
// TODO Log Keep Day threshold from Settings
|
||||
// TODO Move This task creation outside of PlanFiles class
|
||||
plugin.getRunnableFactory().create("Logs folder Clean Task",
|
||||
new LogsFolderCleanTask(getLogsFolder(), 5, plugin.getPluginLogger())
|
||||
).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
} catch (IOException e) {
|
||||
throw new EnableException("Failed to create config.yml", e);
|
||||
}
|
||||
|
|
|
@ -33,17 +33,17 @@ public class BukkitTaskSystem extends ServerTaskSystem {
|
|||
NetworkPageRefreshTask networkPageRefreshTask,
|
||||
BootAnalysisTask bootAnalysisTask,
|
||||
PeriodicAnalysisTask periodicAnalysisTask,
|
||||
PingCountTimer pingCountTimer
|
||||
PingCountTimer pingCountTimer,
|
||||
LogsFolderCleanTask logsFolderCleanTask
|
||||
) {
|
||||
super(
|
||||
runnableFactory,
|
||||
Check.isPaperAvailable()
|
||||
? paperTPSCountTimer
|
||||
: bukkitTPSCountTimer,
|
||||
Check.isPaperAvailable() ? paperTPSCountTimer : bukkitTPSCountTimer,
|
||||
config,
|
||||
networkPageRefreshTask,
|
||||
bootAnalysisTask,
|
||||
periodicAnalysisTask
|
||||
periodicAnalysisTask,
|
||||
logsFolderCleanTask
|
||||
);
|
||||
this.plugin = plugin;
|
||||
this.pingCountTimer = pingCountTimer;
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.djrapitops.plugin.api.TimeAmount;
|
|||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* TaskSystem responsible for registering tasks for Bungee.
|
||||
|
@ -21,18 +22,21 @@ public class BungeeTaskSystem extends TaskSystem {
|
|||
|
||||
private final EnableConnectionTask enableConnectionTask;
|
||||
private final NetworkPageRefreshTask networkPageRefreshTask;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
|
||||
@Inject
|
||||
public BungeeTaskSystem(
|
||||
RunnableFactory runnableFactory,
|
||||
BungeeTPSCountTimer bungeeTPSCountTimer,
|
||||
EnableConnectionTask enableConnectionTask,
|
||||
NetworkPageRefreshTask networkPageRefreshTask
|
||||
NetworkPageRefreshTask networkPageRefreshTask,
|
||||
LogsFolderCleanTask logsFolderCleanTask
|
||||
) {
|
||||
super(runnableFactory, bungeeTPSCountTimer);
|
||||
|
||||
this.enableConnectionTask = enableConnectionTask;
|
||||
this.networkPageRefreshTask = networkPageRefreshTask;
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,7 +46,8 @@ public class BungeeTaskSystem extends TaskSystem {
|
|||
|
||||
private void registerTasks() {
|
||||
registerTask(enableConnectionTask).runTaskAsynchronously();
|
||||
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
|
||||
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
|
||||
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.toTicks(1L, TimeUnit.SECONDS));
|
||||
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(1500, TimeAmount.toTicks(5L, TimeUnit.MINUTES));
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package com.djrapitops.plan.system.tasks;
|
||||
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -14,6 +19,7 @@ import java.util.concurrent.TimeUnit;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class LogsFolderCleanTask extends AbsRunnable {
|
||||
|
||||
private final int keepLogDayThreshold;
|
||||
|
@ -21,9 +27,14 @@ public class LogsFolderCleanTask extends AbsRunnable {
|
|||
private final File folder;
|
||||
private final PluginLogger logger;
|
||||
|
||||
public LogsFolderCleanTask(File folder, int keepLogDayThreshold, PluginLogger logger) {
|
||||
this.folder = folder;
|
||||
this.keepLogDayThreshold = keepLogDayThreshold;
|
||||
@Inject
|
||||
public LogsFolderCleanTask(
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.folder = files.getLogsFolder();
|
||||
this.keepLogDayThreshold = config.getNumber(Settings.KEEP_LOGS_DAYS);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ import com.djrapitops.plan.system.tasks.server.PeriodicAnalysisTask;
|
|||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Abstracted TaskSystem implementation for both Bukkit and Sponge.
|
||||
*
|
||||
|
@ -17,8 +19,9 @@ public abstract class ServerTaskSystem extends TaskSystem {
|
|||
|
||||
private final PlanConfig config;
|
||||
private final NetworkPageRefreshTask networkPageRefreshTask;
|
||||
private final BootAnalysisTask bootAnalysisTask;
|
||||
private final PeriodicAnalysisTask periodicAnalysisTask;
|
||||
protected BootAnalysisTask bootAnalysisTask;
|
||||
private final LogsFolderCleanTask logsFolderCleanTask;
|
||||
|
||||
public ServerTaskSystem(
|
||||
RunnableFactory runnableFactory,
|
||||
|
@ -26,13 +29,14 @@ public abstract class ServerTaskSystem extends TaskSystem {
|
|||
PlanConfig config,
|
||||
NetworkPageRefreshTask networkPageRefreshTask,
|
||||
BootAnalysisTask bootAnalysisTask,
|
||||
PeriodicAnalysisTask periodicAnalysisTask
|
||||
) {
|
||||
PeriodicAnalysisTask periodicAnalysisTask,
|
||||
LogsFolderCleanTask logsFolderCleanTask) {
|
||||
super(runnableFactory, tpsCountTimer);
|
||||
this.config = config;
|
||||
this.networkPageRefreshTask = networkPageRefreshTask;
|
||||
this.bootAnalysisTask = bootAnalysisTask;
|
||||
this.periodicAnalysisTask = periodicAnalysisTask;
|
||||
this.logsFolderCleanTask = logsFolderCleanTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,25 +48,16 @@ public abstract class ServerTaskSystem extends TaskSystem {
|
|||
// Analysis refresh settings
|
||||
int analysisRefreshMinutes = config.getNumber(Settings.ANALYSIS_AUTO_REFRESH);
|
||||
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
|
||||
long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks();
|
||||
long analysisPeriod = TimeAmount.toTicks(analysisRefreshMinutes, TimeUnit.MINUTES);
|
||||
|
||||
registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
|
||||
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(20L, 5L * TimeAmount.MINUTE.ticks());
|
||||
registerTask(bootAnalysisTask).runTaskLaterAsynchronously(30L * TimeAmount.SECOND.ticks());
|
||||
registerTask(tpsCountTimer).runTaskTimer(1000, TimeAmount.toTicks(1L, TimeUnit.SECONDS));
|
||||
registerTask(networkPageRefreshTask).runTaskTimerAsynchronously(20L, TimeAmount.toTicks(5L, TimeUnit.MINUTES));
|
||||
registerTask(bootAnalysisTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
|
||||
if (analysisRefreshTaskIsEnabled) {
|
||||
registerTask(periodicAnalysisTask).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelBootAnalysis() {
|
||||
try {
|
||||
if (bootAnalysisTask != null) {
|
||||
bootAnalysisTask.cancel();
|
||||
bootAnalysisTask = null;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
/* Ignored */
|
||||
}
|
||||
registerTask(logsFolderCleanTask).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
|
@ -24,7 +24,8 @@ public class SpongeTaskSystem extends ServerTaskSystem {
|
|||
SpongeTPSCountTimer spongeTPSCountTimer,
|
||||
NetworkPageRefreshTask networkPageRefreshTask,
|
||||
BootAnalysisTask bootAnalysisTask,
|
||||
PeriodicAnalysisTask periodicAnalysisTask
|
||||
PeriodicAnalysisTask periodicAnalysisTask,
|
||||
LogsFolderCleanTask logsFolderCleanTask
|
||||
) {
|
||||
super(
|
||||
runnableFactory,
|
||||
|
@ -32,7 +33,8 @@ public class SpongeTaskSystem extends ServerTaskSystem {
|
|||
config,
|
||||
networkPageRefreshTask,
|
||||
bootAnalysisTask,
|
||||
periodicAnalysisTask
|
||||
periodicAnalysisTask,
|
||||
logsFolderCleanTask
|
||||
);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user