Scheduled Export of Server pages

This commit is contained in:
Rsl1122 2019-09-01 16:43:42 +03:00
parent d1123525ac
commit 3a3ba7e801
6 changed files with 118 additions and 25 deletions

View File

@ -0,0 +1,98 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.delivery.upkeep.ExportTask;
import com.djrapitops.plan.identification.Server;
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.queries.objects.ServerQueries;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
* Schedules export tasks so that they are not all run at once.
*
* @author Rsl1122
*/
@Singleton
public class ExportScheduler {
private final PlanConfig config;
private final DBSystem dbSystem;
private final TaskSystem taskSystem;
private final Exporter exporter;
private final PluginLogger logger;
private final ErrorHandler errorHandler;
@Inject
public ExportScheduler(
PlanConfig config,
DBSystem dbSystem,
TaskSystem taskSystem,
Exporter exporter,
PluginLogger logger,
ErrorHandler errorHandler
) {
this.config = config;
this.dbSystem = dbSystem;
this.taskSystem = taskSystem;
this.exporter = exporter;
this.logger = logger;
this.errorHandler = errorHandler;
}
public void scheduleExport() {
scheduleServerPageExport();
}
public void scheduleServerPageExport() {
if (!config.get(ExportSettings.SERVER_PAGE)) return;
Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection());
int serverCount = servers.size();
if (serverCount == 0) return;
long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS);
long offset = period / serverCount;
Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst();
proxy.ifPresent(server -> taskSystem.registerTask("Server export",
new ExportTask(exporter, exporter -> exporter.exportServerPage(server), logger, errorHandler))
.runTaskTimerAsynchronously(0L, period)
);
int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network.
for (Server server : servers) {
taskSystem.registerTask("Server export",
new ExportTask(exporter, exporter -> exporter.exportServerPage(server), logger, errorHandler))
.runTaskTimerAsynchronously(offset * offsetMultiplier, period);
offsetMultiplier++;
}
}
}

View File

@ -40,6 +40,7 @@ public class ExportSystem implements SubSystem {
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
private final Processing processing;
private final ExportScheduler exportScheduler;
private final HtmlExport htmlExport;
@Inject
@ -48,12 +49,14 @@ public class ExportSystem implements SubSystem {
DBSystem dbSystem,
ServerInfo serverInfo,
Processing processing,
ExportScheduler exportScheduler,
HtmlExport htmlExport
) {
this.config = config;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.processing = processing;
this.exportScheduler = exportScheduler;
this.htmlExport = htmlExport;
}
@ -65,20 +68,11 @@ public class ExportSystem implements SubSystem {
return;
}
if (config.isTrue(ExportSettings.JS_AND_CSS)) {
// processing.submitNonCritical(htmlExport::exportJs);
// processing.submitNonCritical(htmlExport::exportCss);
// processing.submitNonCritical(htmlExport::exportPlugins);
}
exportScheduler.scheduleExport();
if (config.isTrue(ExportSettings.PLAYERS_PAGE)) {
processing.submitNonCritical(htmlExport::exportPlayersPage);
}
if (config.isTrue(ExportSettings.PLAYER_PAGES)) {
processing.submitNonCritical(htmlExport::exportAvailablePlayers);
}
if (config.isTrue(ExportSettings.SERVER_PAGE)) {
processing.submitNonCritical(htmlExport::exportAvailableServerPages);
}
}
@Override

View File

@ -132,7 +132,9 @@ public class ConfigUpdater {
new ConfigChange.Removed("Display_options.Sessions.Show_most_played_world_in_title"),
new ConfigChange.Removed("Time.Thresholds.Activity_index.Login_threshold"),
new ConfigChange.Removed("Time.Periodic_tasks.Clean_caches_every"),
new ConfigChange.Removed("Display_options.Show_player_IPs")
new ConfigChange.Removed("Time.Periodic_tasks.Analysis_refresh_every"),
new ConfigChange.Removed("Display_options.Show_player_IPs"),
new ConfigChange.Removed("Export.Parts.JavaScript_and_CSS")
};
}

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.settings.config.paths;
import com.djrapitops.plan.settings.config.paths.key.BooleanSetting;
import com.djrapitops.plan.settings.config.paths.key.Setting;
import com.djrapitops.plan.settings.config.paths.key.StringSetting;
import com.djrapitops.plan.settings.config.paths.key.TimeSetting;
/**
* {@link Setting} values that are in "Export" section.
@ -29,13 +30,13 @@ public class ExportSettings {
public static final Setting<String> HTML_EXPORT_PATH = new StringSetting("Export.HTML_Export_path");
public static final Setting<String> JSON_EXPORT_PATH = new StringSetting("Export.JSON_Export_path");
public static final Setting<Boolean> JS_AND_CSS = new BooleanSetting("Export.Parts.JavaScript_and_CSS");
public static final Setting<Boolean> PLAYER_PAGES = new BooleanSetting("Export.Parts.Player_pages");
public static final Setting<Boolean> PLAYER_JSON = new BooleanSetting("Export.Parts.Player_JSON");
public static final Setting<Boolean> PLAYERS_PAGE = new BooleanSetting("Export.Parts.Players_page");
public static final Setting<Boolean> SERVER_PAGE = new BooleanSetting("Export.Parts.Server_page");
public static final Setting<Boolean> SERVER_JSON = new BooleanSetting("Export.Parts.Server_JSON");
public static final Setting<Boolean> EXPORT_ON_ONLINE_STATUS_CHANGE = new BooleanSetting("Export.Export_player_on_login_and_logout");
public static final Setting<Long> EXPORT_PERIOD = new TimeSetting("Export.Server_refresh_period");
private ExportSettings() {
/* static variable class */

View File

@ -81,7 +81,6 @@ Time:
# The index is a number from 0 to 5.
# These numbers were calibrated with data of 250 players (Small sample size).
Activity_index:
Login_threshold: 2
Playtime_threshold: 30
Unit: MINUTES
Remove_inactive_player_data_after: 180
@ -96,8 +95,6 @@ Time:
Unit: HOURS
Check_DB_for_server_config_files_every: 1
Unit: MINUTES
Clean_caches_every: 10
Unit: MINUTES
Clean_Database_every: 1
Unit: HOURS
# -----------------------------------------------------
@ -114,7 +111,6 @@ Display_options:
Show_on_server_page: 2500
Show_on_players_page: 25000
Open_player_links_in_new_tab: false
Show_player_IPs: true
Graphs:
Show_gaps_in_data: false
TPS:
@ -161,12 +157,12 @@ World_aliases:
# These settings will make Plan write .js, .css, .json and .html files to some location on disk.
# Relative path will render to /plugins/Plan/path
# Make sure user running the server has write permissions to the path.
# On networks export is disabled on Bukkit/Sponge servers.
# -----------------------------------------------------
Export:
HTML_Export_path: 'Analysis Results'
JSON_Export_path: 'Raw JSON'
Parts:
JavaScript_and_CSS: false
# Player pages/JSON are only written on join/leave.
Player_pages: false
Player_JSON: false
@ -174,6 +170,10 @@ Export:
Server_page: false
Server_JSON: false
Export_player_on_login_and_logout: false
# If there are multiple servers the period is divided evenly to avoid export of all servers at once
# Also affects Players page export
Server_refresh_period: 20
Unit: MINUTES
# -----------------------------------------------------
# These settings affect Plugin data integration.
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false

View File

@ -86,7 +86,6 @@ Time:
# The index is a number from 0 to 5.
# These numbers were calibrated with data of 250 players (Small sample size).
Activity_index:
Login_threshold: 2
Playtime_threshold: 30
Unit: MINUTES
Remove_inactive_player_data_after: 180
@ -97,14 +96,10 @@ Time:
Remove_ping_data_after: 14
Unit: DAYS
Periodic_tasks:
Analysis_refresh_every: 60
Unit: MINUTES
Extension_data_refresh_every: 1
Unit: HOURS
Check_DB_for_server_config_files_every: 1
Unit: MINUTES
Clean_caches_every: 10
Unit: MINUTES
Clean_Database_every: 1
Unit: HOURS
# -----------------------------------------------------
@ -121,7 +116,6 @@ Display_options:
Show_on_server_page: 2500
Show_on_players_page: 25000
Open_player_links_in_new_tab: false
Show_player_IPs: true
Graphs:
Show_gaps_in_data: false
TPS:
@ -168,12 +162,12 @@ World_aliases:
# These settings will make Plan write .js, .css, .json and .html files to some location on disk.
# Relative path will render to /plugins/Plan/path
# Make sure user running the server has write permissions to the path.
# On networks export is disabled on Bukkit/Sponge servers.
# -----------------------------------------------------
Export:
HTML_Export_path: 'Analysis Results'
JSON_Export_path: 'Raw JSON'
Parts:
JavaScript_and_CSS: false
# Player pages/JSON are only written on join/leave.
Player_pages: false
Player_JSON: false
@ -182,6 +176,10 @@ Export:
Server_JSON: false
# All player pages/JSON can be exported by using /plan m export players
Export_player_on_login_and_logout: false
# If there are multiple servers the period is divided evenly to avoid export of all servers at once
# Also affects Players page export
Server_refresh_period: 20
Unit: MINUTES
# -----------------------------------------------------
# These settings affect Plugin data integration.
# If a plugin is causing issues the integration can be disabled by setting Plugin_name.Enabled: false