️ refactor: 将排序的服务器列表的锁拆分出来

This commit is contained in:
naiba
2021-01-17 22:18:36 +08:00
parent d059835877
commit bf71aeaaf9
5 changed files with 24 additions and 17 deletions

View File

@@ -31,7 +31,7 @@ func DispatchTask(duration time.Duration) {
var tasks []model.Monitor
var hasAliveAgent bool
dao.DB.Find(&tasks)
dao.ServerLock.RLock()
dao.SortedServerLock.RLock()
startedAt := time.Now()
for i := 0; i < len(tasks); i++ {
if index >= uint64(len(dao.SortedServerList)) {
@@ -50,7 +50,7 @@ func DispatchTask(duration time.Duration) {
dao.SortedServerList[index].TaskStream.Send(tasks[i].PB())
index++
}
dao.ServerLock.RUnlock()
dao.SortedServerLock.RUnlock()
time.Sleep(time.Until(startedAt.Add(duration)))
}
}