refactor: 修复潜在bug、补全许可声明、添加类型注解、同步文档

This commit is contained in:
2026-06-08 11:35:51 +08:00
parent b43527c52e
commit 60176fa316
10 changed files with 138 additions and 14 deletions
+16 -5
View File
@@ -36,6 +36,17 @@ def main
MethodExecutor.record("info", "mainloop", "MineSentinel started, entering mainloop.")
require_relative 'updates'
begin
upd_result = UpdateManager.check
if upd_result[:status] == :NewerAvailable
MethodExecutor.record("info", "updates", "Update #{upd_result[:version]} available, please check the git repo for details.")
end
rescue => check_error
MethodExecutor.record("error", "updates", "#{check_error.to_s}")
end
# 初次启动:MineSentinel 先于 minecraft 启动(systemd Before=),
# 等待服务器端口就绪,避免误判为崩溃
MethodExecutor.record("info", "mainloop",
@@ -56,18 +67,18 @@ end
# Functional mainloop.
def main_once
chkrslts = []
for i in 0..TRY_TIMES
(0..TRY_TIMES).each do
chkrslt = ServerStatusDetector::MinecraftServer.self_diag
chkrslts.append(chkrslt)
end
if chkrslts.all? { |chkrslt_in| chkrslt_in[:type] }
MethodExecutor.record("debug", "mainloop", "Server health check passed.")
else
for chkrslt_in in chkrslts
MethodExecutor.record("warn", "mainloop", "Server health check FAILED: #{chkrslt_in[:message]}")
chkrslts.each do |result|
MethodExecutor.record("warn", "mainloop", "Server health check FAILED: #{result[:message]}")
end
MethodExecutor.record("info", "mainloop", "Checked #{TRY_TIMES} time.")
if chkrslts.any? { |chkrslt_in| chkrslt_in[:operation] == "Record" }
if chkrslts.any? { |chkrslt_in| chkrslt_in[:operation].include?("Record") }
MethodExecutor.record("warn", "mainloop", "Action: Record -> Server died!")
if chkrslts.any? { |chkrslt_in| chkrslt_in[:message] == "Server died for unknown reason, and will be restarted." }
MethodExecutor.record("info", "mainloop", "Action: ForceResetServerProcess triggered.")
@@ -98,6 +109,6 @@ begin
rescue => e
# 强制输出到stderr
$stderr.puts "[CRITICAL] Unhandled exception: #{e.message}"
$stderr.puts e.backtrace.join("\n")
$stderr.puts e.backtrace&.join("\n")
exit 1
end