From 2789603657526f8da8522c2a8f1c442773030cdb Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 29 Apr 2024 06:57:24 +0100 Subject: [PATCH] oopsie --- Dockerfile | 3 +++ .../fascinated/piaservers/pia/PiaManager.java | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index c7b0d5b..f81e322 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,5 +25,8 @@ WORKDIR /home/container # Copy the built jar file from the builder stage COPY --from=builder /home/container/target/PIA-Servers.jar . +# Copy the old servers.json file +COPY --from=builder /home/container/servers.json . + # Run the jar file CMD java -jar PIA-Servers.jar -Djava.awt.headless=true \ No newline at end of file diff --git a/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java b/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java index 9db4f5c..c384500 100644 --- a/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java +++ b/src/main/java/cc/fascinated/piaservers/pia/PiaManager.java @@ -27,12 +27,13 @@ public class PiaManager { private static final String PIA_OPENVPN_CONFIGS_URL = "https://www.privateinternetaccess.com/openvpn/openvpn.zip"; private static final long REMOVAL_THRESHOLD = TimeUnit.DAYS.toMicros(14); // 2 weeks public static Set SERVERS = new HashSet<>(); + private static Path README_PATH; @SneakyThrows public PiaManager() { File serversFile = new File("servers.json"); if (!serversFile.exists()) { - System.out.println("serversFile.json does not exist, creating..."); + System.out.println("servers.json does not exist, creating..."); serversFile.createNewFile(); } // Load the serversFile from the file @@ -43,16 +44,22 @@ public class PiaManager { GitUtils.cloneRepo(); // Clone the repository + // Update the servers every 5 minutes new Timer().scheduleAtFixedRate(new TimerTask() { @Override public void run() { updateServers(serversFile); // Update the servers - Path readmePath = ReadMeManager.updateReadme(); // Update the README.md - - // Commit the changes to the git repository - GitUtils.commitFiles("Scheduled update", serversFile.toPath(), readmePath); + README_PATH = ReadMeManager.updateReadme(); // Update the README.md } }, 0, TimeUnit.MINUTES.toMillis(5)); + + // Commit the files every hour + new Timer().scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + GitUtils.commitFiles("Scheduled update", serversFile.toPath(), README_PATH); // Commit the files + } + }, 0, TimeUnit.HOURS.toMillis(1)); } @SneakyThrows