️ improve: 服务监控相关优化

This commit is contained in:
naiba
2021-01-16 18:04:47 +08:00
parent 161102a37b
commit df0eca5a74
6 changed files with 109 additions and 107 deletions

View File

@@ -32,6 +32,7 @@ func DispatchTask(duration time.Duration) {
var hasAliveAgent bool
dao.DB.Find(&tasks)
dao.ServerLock.RLock()
startedAt := time.Now()
for i := 0; i < len(tasks); i++ {
if index >= uint64(len(dao.SortedServerList)) {
index = 0
@@ -50,6 +51,6 @@ func DispatchTask(duration time.Duration) {
index++
}
dao.ServerLock.RUnlock()
time.Sleep(duration)
time.Sleep(time.Until(startedAt.Add(duration)))
}
}