You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
package app.updates;
|
|
|
|
import app.entities.Stats;
|
|
import jakarta.annotation.PostConstruct;
|
|
import org.jobrunr.jobs.annotations.Job;
|
|
import org.jobrunr.scheduling.JobScheduler;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@Component
|
|
public class PlayersUpdater {
|
|
Stats stats;
|
|
ApplicationContext context;
|
|
JobScheduler jobScheduler;
|
|
|
|
@Value("${backend.updates.a2s}")
|
|
private boolean update = false;
|
|
|
|
@Autowired
|
|
public PlayersUpdater(Stats stats,
|
|
ApplicationContext context,
|
|
JobScheduler jobScheduler) {
|
|
this.stats = stats;
|
|
this.context = context;
|
|
this.jobScheduler = jobScheduler;
|
|
}
|
|
|
|
@PostConstruct
|
|
public void updateValues() {
|
|
if (update) {
|
|
stats.getServers().forEach((server_name, server) -> {
|
|
jobScheduler.enqueue(() -> UpdatePlayersOnServer(server_name));
|
|
jobScheduler.scheduleRecurrently("backend.stats.info.update." + server_name, "* * * * *", () -> UpdatePlayersOnServer(server_name));
|
|
});
|
|
}
|
|
}
|
|
|
|
@Job(name = "Update A2S data on: %0")
|
|
public void UpdatePlayersOnServer(String server_name) {
|
|
stats.RefreshServerA2SData(context, server_name);
|
|
}
|
|
}
|
|
|