Skip to content

Commit eda364d

Browse files
authored
fix(master): replace hardcoded sleep duration with baseDuration constant for consistency
1 parent c9222cb commit eda364d

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

internal/master.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ import (
3131

3232
// 常量定义
3333
const (
34-
openAPIVersion = "v1" // OpenAPI版本
35-
stateFilePath = "gob" // 实例状态持久化文件路径
36-
stateFileName = "nodepass.gob" // 实例状态持久化文件名
37-
sseRetryTime = 3000 // 重试间隔时间(毫秒)
38-
apiKeyID = "********" // API Key的特殊ID
39-
tcpingSemLimit = 10 // TCPing最大并发数
34+
openAPIVersion = "v1" // OpenAPI版本
35+
stateFilePath = "gob" // 实例状态持久化文件路径
36+
stateFileName = "nodepass.gob" // 实例状态持久化文件名
37+
sseRetryTime = 3000 // 重试间隔时间(毫秒)
38+
apiKeyID = "********" // API Key的特殊ID
39+
tcpingSemLimit = 10 // TCPing最大并发数
40+
baseDuration = 100 * time.Millisecond // 基准持续时间
4041
)
4142

4243
// Swagger UI HTML模板
@@ -479,7 +480,7 @@ func (m *Master) Shutdown(ctx context.Context) error {
479480
})
480481

481482
// 等待所有订阅者处理完关闭事件
482-
time.Sleep(100 * time.Millisecond)
483+
time.Sleep(baseDuration)
483484

484485
// 关闭所有订阅者通道
485486
m.subscribers.Range(func(key, value any) bool {
@@ -732,7 +733,7 @@ func getLinuxSysInfo() SystemInfo {
732733
return
733734
}
734735
idle1, total1 := readStat()
735-
time.Sleep(100 * time.Millisecond)
736+
time.Sleep(baseDuration)
736737
idle2, total2 := readStat()
737738
numCPU := runtime.NumCPU()
738739
if deltaIdle, deltaTotal := idle2-idle1, total2-total1; deltaTotal > 0 && numCPU > 0 {
@@ -874,7 +875,7 @@ func (m *Master) handleInstances(w http.ResponseWriter, r *http.Request) {
874875

875876
// 保存实例状态
876877
go func() {
877-
time.Sleep(100 * time.Millisecond)
878+
time.Sleep(baseDuration)
878879
m.saveState()
879880
}()
880881
writeJSON(w, http.StatusCreated, instance)
@@ -1025,7 +1026,7 @@ func (m *Master) handlePutInstance(w http.ResponseWriter, r *http.Request, id st
10251026
// 如果实例正在运行,先停止它
10261027
if instance.Status == "running" {
10271028
m.stopInstance(instance)
1028-
time.Sleep(100 * time.Millisecond)
1029+
time.Sleep(baseDuration)
10291030
}
10301031

10311032
// 更新实例URL和类型
@@ -1041,7 +1042,7 @@ func (m *Master) handlePutInstance(w http.ResponseWriter, r *http.Request, id st
10411042

10421043
// 保存实例状态
10431044
go func() {
1044-
time.Sleep(100 * time.Millisecond)
1045+
time.Sleep(baseDuration)
10451046
m.saveState()
10461047
}()
10471048
writeJSON(w, http.StatusOK, instance)
@@ -1072,7 +1073,7 @@ func (m *Master) processInstanceAction(instance *Instance, action string) {
10721073
if instance.Status == "running" {
10731074
go func() {
10741075
m.stopInstance(instance)
1075-
time.Sleep(100 * time.Millisecond)
1076+
time.Sleep(baseDuration)
10761077
m.startInstance(instance)
10771078
}()
10781079
} else {
@@ -1352,7 +1353,7 @@ func (m *Master) stopInstance(instance *Instance) {
13521353
} else {
13531354
instance.cmd.Process.Signal(syscall.SIGTERM)
13541355
}
1355-
time.Sleep(100 * time.Millisecond)
1356+
time.Sleep(baseDuration)
13561357
}
13571358

13581359
// 关闭停止通道

0 commit comments

Comments
 (0)