feat: Add 'ScheduledTaskQueueSize' options

This commit is contained in:
rainzm
2020-06-09 15:54:35 +08:00
parent 8a69558c86
commit 3ea4beeb8e
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -31,6 +31,7 @@ import (
"yunion.io/x/onecloud/pkg/apis"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
cop "yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
@@ -549,7 +550,12 @@ func (stm *SScheduledTaskManager) timeScope(median time.Time, interval time.Dura
}
}
var timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)
func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
if len(timerQueue) == 0 {
timerQueue = make(chan struct{}, cop.Options.ScheduledTaskQueueSize)
}
// 60 is for fault tolerance
interval := 60 + 30
timeScope := stm.timeScope(time.Now(), time.Duration(interval)*time.Second)
@@ -560,7 +566,6 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
log.Errorf("db.FetchModelObjects error: %s", err.Error())
return
}
timerQueue := make(chan struct{}, 20)
log.Debugf("timeScope: start: %s, end: %s", timeScope.Start, timeScope.End)
for i := range sts {
st := sts[i]
@@ -592,6 +597,7 @@ func (stm *SScheduledTaskManager) Timer(ctx context.Context, userCred mcclient.T
}
}(ctx)
}
// wait all finish
}
func init() {
+2
View File
@@ -136,6 +136,8 @@ type ComputeOptions struct {
GuestTemplateCheckInterval int `help:"interval between two consecutive inspections of Guest Template in hour unit" default:"12"`
ScheduledTaskQueueSize int `help:"the maximum number of scheduled tasks that are being executed simultaneously" default:"100"`
SCapabilityOptions
SASControllerOptions
common_options.CommonOptions