mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix code
This commit is contained in:
@@ -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)
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user