Skip to content

Commit cf605a0

Browse files
committedSep 5, 2024
script: +update_cache.
1 parent 306b019 commit cf605a0

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed
 

‎script/load_mission/load_mission.py

+34-33
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44
import re
55
import json
66

7+
def print_endpoint(endpoint: str, name: str):
8+
print("update {} endpoint: {}".format(name, endpoint))
9+
10+
def update_cache(endpoint: str, name: str):
11+
print("Updating {} cache...".format(name))
12+
r = requests.get(endpoint)
13+
try:
14+
res = r.json()
15+
if res["code"] != 200:
16+
print("Server returned an error: ", res)
17+
input("Press enter to exit...")
18+
sys.exit(1)
19+
else:
20+
print("Success! time: {}ms".format(res["data"]["time_ms"]))
21+
except json.JSONDecodeError:
22+
print("Invalid response from server: ", r.text)
23+
input("Press enter to exit...")
24+
sys.exit(1)
25+
26+
def update_all_cache(admin_endpoint: str):
27+
update_mission_kpi_endpoint = "{}/update_mission_kpi".format(admin_endpoint)
28+
update_endpoint = "{}/update_essential".format(admin_endpoint)
29+
update_damage_endpoint = "{}/update_damage".format(admin_endpoint)
30+
update_general_endpoint = "{}/update_general".format(admin_endpoint)
31+
32+
update_list = [(update_mission_kpi_endpoint, "mission kpi"), (update_endpoint, "essential"), (update_damage_endpoint, "damage"), (update_general_endpoint, "general")]
33+
34+
for endpoint, name in update_list:
35+
print_endpoint(endpoint, name)
36+
for endpoint, name in update_list:
37+
update_cache(endpoint, name)
38+
39+
740
source_addr = "https://github.com/saitewasreset/DRG_MissionMonitor"
841

942
print("Mission Monitor: load_mission")
@@ -37,14 +70,10 @@
3770

3871
already_uploaded_endpoint = "{}/mission_list".format(admin_endpoint)
3972
upload_endpoint = "{}/load_mission".format(admin_endpoint)
40-
update_endpoint = "{}/update_essential".format(admin_endpoint)
41-
update_damage_endpoint = "{}/update_damage".format(admin_endpoint)
4273

4374
print("log path: {}".format(log_path))
4475
print("already uploaded endpoint: {}".format(already_uploaded_endpoint))
4576
print("upload endpoint: {}".format(upload_endpoint))
46-
print("update endpoint: {}".format(update_endpoint))
47-
print("update damage endpoint: {}".format(update_damage_endpoint))
4877

4978
to_load_list = []
5079

@@ -102,35 +131,7 @@
102131
input("Press enter to exit...")
103132
sys.exit(1)
104133

105-
print("Updating essential cache...")
106-
r = requests.get(update_endpoint)
107-
try:
108-
res = r.json()
109-
if res["code"] != 200:
110-
print("Server returned an error: ", res)
111-
input("Press enter to exit...")
112-
sys.exit(1)
113-
else:
114-
print("Success!")
115-
except json.JSONDecodeError:
116-
print("Invalid response from server: ", r.text)
117-
input("Press enter to exit...")
118-
sys.exit(1)
119-
120-
print("Updating damage cache...")
121-
r = requests.get(update_damage_endpoint)
122-
try:
123-
res = r.json()
124-
if res["code"] != 200:
125-
print("Server returned an error: ", res)
126-
input("Press enter to exit...")
127-
sys.exit(1)
128-
else:
129-
print("Success!")
130-
except json.JSONDecodeError:
131-
print("Invalid response from server: ", r.text)
132-
input("Press enter to exit...")
133-
sys.exit(1)
134+
update_all_cache(admin_endpoint)
134135

135136
print("Rock and stone!")
136137
input("Press enter to exit...")

0 commit comments

Comments
 (0)
Please sign in to comment.