mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add dir calc to separtate schedule- reduce latency
This commit is contained in:
parent
14a2f28818
commit
0afa2cfd97
@ -138,7 +138,10 @@ class ServerInstance:
|
||||
)
|
||||
self.tz = "Europe/London"
|
||||
self.server_scheduler = BackgroundScheduler(timezone=str(self.tz))
|
||||
self.dir_scheduler = BackgroundScheduler(timezone=str(self.tz))
|
||||
self.server_scheduler.start()
|
||||
self.dir_scheduler.start()
|
||||
self.start_dir_calc_task()
|
||||
self.backup_thread = threading.Thread(
|
||||
target=self.a_backup_server, daemon=True, name=f"backup_{self.name}"
|
||||
)
|
||||
@ -1374,6 +1377,20 @@ class ServerInstance:
|
||||
for user in server_users:
|
||||
self.helper.websocket_helper.broadcast_user(user, "remove_spinner", {})
|
||||
|
||||
def start_dir_calc_task(self):
|
||||
server_dt = HelperServers.get_server_data_by_id(self.server_id)
|
||||
self.server_size = self.stats.get_server_dir_size(server_dt["path"])
|
||||
self.dir_scheduler.add_job(
|
||||
self.calc_dir_size,
|
||||
"interval",
|
||||
minutes=self.helper.get_setting("dir_size_poll_freq_minutes"),
|
||||
id=str(self.server_id) + "_dir_poll",
|
||||
)
|
||||
|
||||
def calc_dir_size(self):
|
||||
server_dt = HelperServers.get_server_data_by_id(self.server_id)
|
||||
self.server_size = self.stats.get_server_dir_size(server_dt["path"])
|
||||
|
||||
# **********************************************************************************
|
||||
# Minecraft Servers Statistics
|
||||
# **********************************************************************************
|
||||
@ -1472,9 +1489,6 @@ class ServerInstance:
|
||||
# get our server object, settings and data dictionaries
|
||||
self.reload_server_settings()
|
||||
|
||||
# world data
|
||||
server_path = server["path"]
|
||||
|
||||
# process stats
|
||||
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
|
||||
|
||||
@ -1515,7 +1529,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": ping_data.get("online", False),
|
||||
@ -1533,7 +1547,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": False,
|
||||
@ -1603,7 +1617,6 @@ class ServerInstance:
|
||||
|
||||
# world data
|
||||
server_name = server_dt["server_name"]
|
||||
server_path = server_dt["path"]
|
||||
|
||||
# process stats
|
||||
p_stats = Stats._try_get_process_stats(self.process, self.check_running())
|
||||
@ -1636,7 +1649,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": ping_data.get("online", False),
|
||||
@ -1665,7 +1678,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": ping_data["online"],
|
||||
@ -1684,7 +1697,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": False,
|
||||
@ -1703,7 +1716,7 @@ class ServerInstance:
|
||||
"mem": p_stats.get("memory_usage", 0),
|
||||
"mem_percent": p_stats.get("mem_percentage", 0),
|
||||
"world_name": server_name,
|
||||
"world_size": Stats.get_world_size(server_path),
|
||||
"world_size": self.server_size,
|
||||
"server_port": server_port,
|
||||
"int_ping_results": int_data,
|
||||
"online": False,
|
||||
|
Loading…
Reference in New Issue
Block a user