执行定时任务时自动根据负载进行延后执行

This commit is contained in:
刘祥超
2024-04-12 21:13:19 +08:00
parent fe069762bb
commit f526665633
8 changed files with 35 additions and 13 deletions

View File

@@ -140,3 +140,13 @@ func calculateDiskMaxWrites() {
DiskMaxWrites = 4
}
}
// WaitLoad wait system load to downgrade
func WaitLoad(maxLoad float64, maxLoops int, delay time.Duration) {
for i := 0; i < maxLoops; i++ {
stat, err := load.Avg()
if err == nil && stat.Load1 > maxLoad {
time.Sleep(delay)
}
}
}