This commit is contained in:
Braydon 2024-04-29 01:27:21 -04:00
parent e20761da9f
commit 307a471dd9
2 changed files with 21 additions and 25 deletions

View File

@ -2,7 +2,7 @@ name: Sync PIA Servers
on: on:
schedule: schedule:
- cron: "*/15 * * * *" - cron: "*/20 * * * *"
push: push:
branches: ["master"] branches: ["master"]
paths: [".gitea/workflows/sync-servers.yml", "src/**", "pom.xml"] paths: [".gitea/workflows/sync-servers.yml", "src/**", "pom.xml"]

View File

@ -32,25 +32,14 @@ public final class PIAServerList {
@SneakyThrows @SneakyThrows
public static void main(@NonNull String[] args) { public static void main(@NonNull String[] args) {
Map<String, String> regionAddresses = getRegionAddresses(); // Get region address from PIA Map<String, String> regionAddresses = getRegionAddresses(); // Get region address from PIA
Set<PIAServer> servers = new HashSet<>();
for (int i = 0; i < TOTAL_RUNS; i++) { for (int i = 0; i < TOTAL_RUNS; i++) {
int before = servers.size(); Set<PIAServer> servers = getNewServers(regionAddresses); // Get the new servers from PIA
servers.addAll(getNewServers(regionAddresses)); // Add new servers from PIA
System.out.println("Added " + (servers.size() - before) + " new server(s) from PIA");
// Sleep for 3 mins
if (i < TOTAL_RUNS - 1) {
System.out.println("Sleeping, waiting for another run...");
Thread.sleep(TimeUnit.MINUTES.toMillis(4L));
}
}
// Delete servers that haven't been seen in more than a week
int before = servers.size(); int before = servers.size();
servers.addAll(loadServersFromFile()); // Load servers from the file servers.addAll(loadServersFromFile()); // Load servers from the file
System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file"); System.out.println("Loaded " + (servers.size() - before) + " server(s) from the servers file");
// Delete servers that haven't been seen in more than a week
before = servers.size(); before = servers.size();
servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L)); servers.removeIf(server -> (System.currentTimeMillis() - server.getLastSeen()) >= TimeUnit.DAYS.toMillis(7L));
System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week"); System.out.println("Removed " + (before - servers.size()) + " server(s) that haven't been seen in more than a week");
@ -64,6 +53,13 @@ public final class PIAServerList {
// Update the README.md file // Update the README.md file
ReadMeManager.update(servers); ReadMeManager.update(servers);
// Sleep before running again
if (i < TOTAL_RUNS - 1) {
System.out.println("Sleeping...");
Thread.sleep(TimeUnit.MINUTES.toMillis(4L));
}
}
} }
/** /**