This commit is contained in:
wanyaoqi
2019-01-22 16:56:47 +08:00
committed by Zexi Li
parent 1bb42ae017
commit 1d2fe321d4
3 changed files with 10 additions and 6 deletions
+6 -2
View File
@@ -1,11 +1,15 @@
package workmanager
import (
"context"
"sync/atomic"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
)
type DelayTaskFunc func(ctx context.Context, params jsonutils.JSONObject)
type SWorkManager struct {
curCount int32
}
@@ -18,11 +22,11 @@ func (w *SWorkManager) done() {
atomic.AddInt32(&w.curCount, -1)
}
func (w *SWorkManager) RunTask(task func()) {
func (w *SWorkManager) DelayTask(task DelayTaskFunc, ctx context.Context, params jsonutils.JSONObject) {
w.add()
go func() {
defer w.done()
task()
task(ctx, params)
}()
}
+3 -3
View File
@@ -29,7 +29,7 @@ func getStatus(ctx context.Context, w http.ResponseWriter, r *http.Request) {
}
func cpusetBalance(ctx context.Context, w http.ResponseWriter, r *http.Request) {
wm.RunTask(func() { guestManger.CpusetBalance(ctx) })
wm.DelayTask(func() { guestManger.CpusetBalance(ctx) })
responseOk(ctx, w)
}
@@ -59,7 +59,7 @@ func deleteGuest(ctx context.Context, w http.ResponseWriter, r *http.Request) {
if err != nil {
response(ctx, w, err)
} else {
wm.RunTask(func() { guest.CleanGuest(ctx, migrated) })
wm.DelayTask(func() { guest.CleanGuest(ctx, migrated) })
response(ctx, w, map[string]bool{"delay_clean": true})
}
}
@@ -69,7 +69,7 @@ func doCreate(ctx context.Context, sid string, body jsonutils.JSONObject) (inter
if err != nil {
return nil, httperrors.NewBadRequestError(err.Error())
}
wm.RunTask(func() { guestManger.DoDeploy(ctx, sid, body, true) })
wm.DelayTask(func() { guestManger.DoDeploy(ctx, sid, body, true) })
return nil, nil
}
+1 -1
View File
@@ -375,7 +375,7 @@ func (s *SKVMGuestInstance) SaveDesc(desc jsonutils.JSONObject) error {
}
func (s *SKVMGuestInstance) StartGuest(ctx context.Context, params jsonutils.JSONObject) {
wm.RunTask(func() {
wm.DelayTask(func() {
s.asyncScriptStart(ctx, params)
})
}