refactor: 修复潜在bug、补全许可声明、添加类型注解、同步文档
This commit is contained in:
@@ -20,6 +20,10 @@ module ServerStatusDetector
|
||||
|
||||
class TcpServer
|
||||
|
||||
# @param host [String]
|
||||
# @param port [Integer]
|
||||
# @param timeout [Integer]
|
||||
# @return [Hash{Symbol=>Integer, Symbol=>Symbol, Symbol=>Float,nil}]
|
||||
def self.test_port(host = '127.0.0.1', port = 25565, timeout = 10)
|
||||
result = {
|
||||
port: port,
|
||||
@@ -55,6 +59,7 @@ module ServerStatusDetector
|
||||
|
||||
class MinecraftServer < TcpServer # 继承为TcpServer编写的属性和方法
|
||||
|
||||
# @return [Hash{Symbol=>Boolean, Symbol=>Array<String>, Symbol=>String}]
|
||||
def self_diag
|
||||
|
||||
res = test_port('127.0.0.1', 25565)
|
||||
@@ -64,7 +69,7 @@ module ServerStatusDetector
|
||||
puts message
|
||||
return {
|
||||
type: false,
|
||||
operation: ["Record"],
|
||||
operation: %w[Record],
|
||||
message: message,
|
||||
}
|
||||
end # 立刻错误处理是好习惯
|
||||
@@ -82,7 +87,7 @@ module ServerStatusDetector
|
||||
"TCP check timed out.")
|
||||
return {
|
||||
type: false,
|
||||
operation: ["Record"],
|
||||
operation: %w[Record],
|
||||
message: "We sent packet without response."
|
||||
}
|
||||
when :closed
|
||||
@@ -90,9 +95,17 @@ module ServerStatusDetector
|
||||
"TCP port closed — server is down.")
|
||||
return {
|
||||
type: false,
|
||||
operation: ["Record", "ForceResetServerProcess"], # 重启时注意要设置最大尝试次数
|
||||
operation: %w[Record ForceResetServerProcess], # 重启时注意要设置最大尝试次数
|
||||
message: "Server died for unknown reason, and will be restarted."
|
||||
}
|
||||
else
|
||||
MethodExecutor.record("warn", "self_diag",
|
||||
"TCP check returned unexpected status: #{res[:status]}.")
|
||||
return {
|
||||
type: false,
|
||||
operation: %w[Record],
|
||||
message: "Unexpected status: #{res[:status]}."
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user