|
|
@@ -29,18 +29,25 @@ def read_json_file(path, default=None):
|
|
|
default = {}
|
|
|
if not os.path.exists(path):
|
|
|
return default
|
|
|
- with open(path, "r", encoding="utf-8") as f:
|
|
|
- return json.load(f)
|
|
|
+ try:
|
|
|
+ with open(path, "r", encoding="utf-8") as f:
|
|
|
+ return json.load(f)
|
|
|
+ except (ValueError, json.JSONDecodeError):
|
|
|
+ return default
|
|
|
|
|
|
|
|
|
def write_json_file(path, data):
|
|
|
- os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
+ parent = os.path.dirname(path)
|
|
|
+ if parent:
|
|
|
+ os.makedirs(parent, exist_ok=True)
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
|
json.dump(data, f, ensure_ascii=True, indent=2)
|
|
|
|
|
|
|
|
|
def write_text_file(path, data):
|
|
|
- os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
|
+ parent = os.path.dirname(path)
|
|
|
+ if parent:
|
|
|
+ os.makedirs(parent, exist_ok=True)
|
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
|
f.write(data)
|
|
|
|
|
|
@@ -981,8 +988,7 @@ def main():
|
|
|
|
|
|
if cfg.get("healthcheck", {}).get("enabled", False):
|
|
|
check_results = check_domains(filtered, cfg.get("healthcheck", {}))
|
|
|
- selected, _ = choose_domain(filtered, check_results, top_n, [])
|
|
|
- top_candidates = cfst_rows[:top_n]
|
|
|
+ selected, top_candidates = choose_domain(filtered, check_results, top_n, [])
|
|
|
else:
|
|
|
selected = cfst_rows[0]["domain"]
|
|
|
top_candidates = cfst_rows[:top_n]
|
|
|
@@ -1006,12 +1012,14 @@ def main():
|
|
|
scored_records = [r for r in scored_records if r["domain"] in filtered_set]
|
|
|
ranked_scored = rank_scored_records(scored_records, scoring_cfg)
|
|
|
|
|
|
- if cfg.get("healthcheck", {}).get("enabled", True):
|
|
|
+ if cfg.get("healthcheck", {}).get("enabled", False):
|
|
|
check_results = check_domains(filtered, cfg.get("healthcheck", {}))
|
|
|
|
|
|
selected, top_candidates = choose_domain(filtered, check_results, top_n, ranked_scored)
|
|
|
|
|
|
status = "ok"
|
|
|
+ if check_results and all(x["success_ratio"] == 0 for x in check_results):
|
|
|
+ status = "ok_no_healthy"
|
|
|
if not selected and last_good:
|
|
|
selected = last_good
|
|
|
status = "fallback_last_good"
|
|
|
@@ -1077,6 +1085,14 @@ def main():
|
|
|
"source_type": source_type,
|
|
|
},
|
|
|
)
|
|
|
+ write_json_file(
|
|
|
+ vars_file,
|
|
|
+ {
|
|
|
+ vars_value_key: last_good,
|
|
|
+ "UPDATED_AT": now,
|
|
|
+ "STATUS": "error_use_last_good",
|
|
|
+ },
|
|
|
+ )
|
|
|
run_notify(notify_cfg.get("command", ""), last_good, "error_use_last_good")
|
|
|
print(json.dumps({"status": "error_use_last_good", "error": str(e)}, ensure_ascii=True))
|
|
|
return
|