This commit is contained in:
Lee 2024-04-29 06:57:24 +01:00
parent e350b039d2
commit 2789603657
2 changed files with 15 additions and 5 deletions

@ -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

@ -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<PiaServer> 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