Files
waf-platform/EdgeAPI/internal/installers/upgrade_queue.go

26 lines
669 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package installers
// UpgradeQueue 升级队列,控制并发数
type UpgradeQueue struct {
sem chan struct{}
}
// SharedUpgradeQueue 全局升级队列最多5个并发
var SharedUpgradeQueue = NewUpgradeQueue(5)
// NewUpgradeQueue 创建升级队列
func NewUpgradeQueue(maxConcurrent int) *UpgradeQueue {
return &UpgradeQueue{
sem: make(chan struct{}, maxConcurrent),
}
}
// SubmitNodeUpgrade 提交节点升级任务(异步执行,超过并发限制自动排队)
func (q *UpgradeQueue) SubmitNodeUpgrade(nodeId int64, upgradeFunc func(int64) error) {
go func() {
q.sem <- struct{}{}
defer func() { <-q.sem }()
_ = upgradeFunc(nodeId)
}()
}