Fixed image overwriting for export

This commit is contained in:
Rsl1122 2019-09-01 19:05:07 +03:00
parent b67534af20
commit dd57dff4ae
4 changed files with 18 additions and 17 deletions

View File

@ -17,7 +17,6 @@
package com.djrapitops.plan.delivery.export; package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.TaskSystem; import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.delivery.upkeep.ExportTask;
import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.PlanConfig;
import com.djrapitops.plan.settings.config.paths.ExportSettings; import com.djrapitops.plan.settings.config.paths.ExportSettings;
@ -68,9 +67,17 @@ public class ExportScheduler {
public void scheduleExport() { public void scheduleExport() {
scheduleServerPageExport(); scheduleServerPageExport();
schedulePlayersPageExport();
} }
public void scheduleServerPageExport() { private void schedulePlayersPageExport() {
long period = TimeAmount.toTicks(config.get(ExportSettings.EXPORT_PERIOD), TimeUnit.MILLISECONDS);
taskSystem.registerTask("Players page export",
new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler)
).runTaskTimerAsynchronously(0L, period);
}
private void scheduleServerPageExport() {
if (!config.get(ExportSettings.SERVER_PAGE)) return; if (!config.get(ExportSettings.SERVER_PAGE)) return;
Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection()); Collection<Server> servers = dbSystem.getDatabase().query(ServerQueries.fetchPlanServerInformationCollection());
@ -81,15 +88,11 @@ public class ExportScheduler {
long offset = period / serverCount; long offset = period / serverCount;
Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst(); Optional<Server> proxy = servers.stream().filter(Server::isProxy).findFirst();
proxy.ifPresent(server -> taskSystem.registerTask("Server export", proxy.ifPresent(mainServer -> taskSystem.registerTask("Network export",
new ExportTask(exporter, exporter -> exporter.exportServerPage(server), logger, errorHandler)) new ExportTask(exporter, exporter -> exporter.exportServerPage(mainServer), logger, errorHandler))
.runTaskTimerAsynchronously(0L, period) .runTaskTimerAsynchronously(0L, period)
); );
taskSystem.registerTask("Players page export",
new ExportTask(exporter, Exporter::exportPlayersPage, logger, errorHandler)
).runTaskTimerAsynchronously(0L, period);
int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network. int offsetMultiplier = proxy.isPresent() ? 1 : 0; // Delay first server export if on a network.
for (Server server : servers) { for (Server server : servers) {
taskSystem.registerTask("Server export", taskSystem.registerTask("Server export",

View File

@ -14,9 +14,8 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>. * along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.djrapitops.plan.delivery.upkeep; package com.djrapitops.plan.delivery.export;
import com.djrapitops.plan.delivery.export.Exporter;
import com.djrapitops.plan.exceptions.ExportException; import com.djrapitops.plan.exceptions.ExportException;
import com.djrapitops.plan.utilities.java.ThrowingConsumer; import com.djrapitops.plan.utilities.java.ThrowingConsumer;
import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.L;

View File

@ -107,7 +107,7 @@ public class Exporter {
return true; return true;
} catch (IOException | NotFoundException | ParseException e) { } catch (IOException | NotFoundException | ParseException e) {
failedServers.add(serverUUID); failedServers.add(serverUUID);
throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.getMessage(), e); throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e);
} }
} }
@ -127,7 +127,7 @@ public class Exporter {
playerPageExporter.export(toDirectory, playerUUID, playerName); playerPageExporter.export(toDirectory, playerUUID, playerName);
return true; return true;
} catch (IOException | NotFoundException | ParseException e) { } catch (IOException | NotFoundException | ParseException e) {
throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e); throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
} }
} }
@ -139,7 +139,7 @@ public class Exporter {
playersPageExporter.export(toDirectory); playersPageExporter.export(toDirectory);
return true; return true;
} catch (IOException | NotFoundException | ParseException e) { } catch (IOException | NotFoundException | ParseException e) {
throw new ExportException("Failed to export players page, " + e.getMessage(), e); throw new ExportException("Failed to export players page, " + e.toString(), e);
} }
} }
@ -159,7 +159,7 @@ public class Exporter {
playerJSONExporter.export(toDirectory, playerUUID, playerName); playerJSONExporter.export(toDirectory, playerUUID, playerName);
return true; return true;
} catch (IOException e) { } catch (IOException e) {
throw new ExportException("Failed to export player: " + playerName + ", " + e.getMessage(), e); throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e);
} }
} }
} }

View File

@ -59,11 +59,10 @@ abstract class FileExporter {
void export(Path to, Resource resource) throws IOException { void export(Path to, Resource resource) throws IOException {
Files.createDirectories(to.getParent()); Files.createDirectories(to.getParent());
if (Files.exists(to)) Files.delete(to);
Files.createFile(to);
try ( try (
InputStream in = resource.asInputStream(); InputStream in = resource.asInputStream();
OutputStream out = Files.newOutputStream(to) OutputStream out = Files.newOutputStream(to, StandardOpenOption.CREATE)
) { ) {
copy(in, out); copy(in, out);
} }