Move export system startup query to async task

This commit is contained in:
Risto Lahtela 2021-07-11 11:41:40 +03:00
parent 78209e99a6
commit 6a199d3f1f
2 changed files with 25 additions and 20 deletions

View File

@ -17,11 +17,14 @@
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import com.djrapitops.plan.utilities.logging.ErrorLogger;
import net.playeranalytics.plugin.scheduling.PluginRunnable;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.scheduling.TimeAmount;
@ -37,10 +40,11 @@ import java.util.concurrent.TimeUnit;
* @author AuroraLS3
*/
@Singleton
public class ExportScheduler {
public class ExportScheduler extends PluginRunnable {
private final PlanConfig config;
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
private final RunnableFactory runnableFactory;
private final Exporter exporter;
@ -50,18 +54,31 @@ public class ExportScheduler {
public ExportScheduler(
PlanConfig config,
DBSystem dbSystem,
ServerInfo serverInfo,
RunnableFactory runnableFactory,
Exporter exporter,
ErrorLogger errorLogger
) {
this.config = config;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.runnableFactory = runnableFactory;
this.exporter = exporter;
this.errorLogger = errorLogger;
}
public void scheduleExport() {
@Override
public void run() {
scheduleExport();
}
private void scheduleExport() {
Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return;
}
scheduleServerPageExport();
schedulePlayersPageExport();
}

View File

@ -17,10 +17,7 @@
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.SubSystem;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -33,30 +30,21 @@ import javax.inject.Singleton;
@Singleton
public class ExportSystem implements SubSystem {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
private final ExportScheduler exportScheduler;
private final RunnableFactory runnableFactory;
@Inject
public ExportSystem(
DBSystem dbSystem,
ServerInfo serverInfo,
ExportScheduler exportScheduler
ExportScheduler exportScheduler,
RunnableFactory runnableFactory
) {
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.exportScheduler = exportScheduler;
this.runnableFactory = runnableFactory;
}
@Override
public void enable() {
Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return;
}
exportScheduler.scheduleExport();
runnableFactory.create(exportScheduler).runTaskAsynchronously();
}
@Override