mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
1.fix corn run task with empyt context
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
package cronman
|
||||
|
||||
import (
|
||||
"time"
|
||||
"runtime/debug"
|
||||
"context"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_CRON_INTERVAL = 60*time.Second // default resolution is 1 monutes
|
||||
DEFAULT_CRON_INTERVAL = 60 * time.Second // default resolution is 1 monutes
|
||||
)
|
||||
|
||||
type SCronJobManager struct {
|
||||
checkInterval time.Duration
|
||||
timer *time.Timer
|
||||
jobs []SCronJob
|
||||
timer *time.Timer
|
||||
jobs []SCronJob
|
||||
}
|
||||
|
||||
type SCronJob struct {
|
||||
name string
|
||||
name string
|
||||
runInterval time.Duration
|
||||
job func(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
lastRun time.Time
|
||||
job func(ctx context.Context, userCred mcclient.TokenCredential)
|
||||
lastRun time.Time
|
||||
}
|
||||
|
||||
func NewCronJobManager(interval time.Duration) *SCronJobManager {
|
||||
@@ -89,7 +90,7 @@ func runJob(name string, job func(ctx context.Context, userCred mcclient.TokenCr
|
||||
}()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, appctx.APP_CONTEXT_KEY_APPNAME, "Region-Corn-Service")
|
||||
userCred := auth.AdminCredential()
|
||||
job(ctx, userCred)
|
||||
}
|
||||
|
||||
|
||||
@@ -246,17 +246,21 @@ func (manager *STaskManager) NewParallelTask(ctx context.Context, taskName strin
|
||||
}
|
||||
|
||||
func (manager *STaskManager) fetchTask(idStr string) *STask {
|
||||
task, err := db.NewModelObject(manager)
|
||||
iTask, err := db.NewModelObject(manager)
|
||||
if err != nil {
|
||||
log.Errorf("New task object fail: %s", err)
|
||||
return nil
|
||||
}
|
||||
err = manager.Query().Equals("id", idStr).First(task)
|
||||
err = manager.Query().Equals("id", idStr).First(iTask)
|
||||
if err != nil {
|
||||
log.Errorf("GetTask %s fail: %s", idStr, err)
|
||||
return nil
|
||||
}
|
||||
return task.(*STask)
|
||||
task := iTask.(*STask)
|
||||
if task.Params == nil {
|
||||
task.Params = jsonutils.NewDict()
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
func (manager *STaskManager) execTask(taskId string, data jsonutils.JSONObject) {
|
||||
@@ -412,9 +416,11 @@ func (self *STask) GetParentTask() *STask {
|
||||
|
||||
func (self *STask) GetRequestContext() appctx.AppContextData {
|
||||
ctxData := appctx.AppContextData{}
|
||||
ctxJson, _ := self.Params.Get(REQUEST_CONTEXT_KEY)
|
||||
if ctxJson != nil {
|
||||
ctxJson.Unmarshal(&ctxData)
|
||||
if self.Params != nil {
|
||||
ctxJson, _ := self.Params.Get(REQUEST_CONTEXT_KEY)
|
||||
if ctxJson != nil {
|
||||
ctxJson.Unmarshal(&ctxData)
|
||||
}
|
||||
}
|
||||
return ctxData
|
||||
}
|
||||
|
||||
@@ -2581,9 +2581,9 @@ func (self *SGuest) AllowDeleteItem(ctx context.Context, userCred mcclient.Token
|
||||
func (self *SGuest) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
overridePendingDelete := false
|
||||
purge := false
|
||||
if data != nil {
|
||||
overridePendingDelete = jsonutils.QueryBoolean(data, "override_pending_delete", false)
|
||||
purge = jsonutils.QueryBoolean(data, "purge", false)
|
||||
if query != nil {
|
||||
overridePendingDelete = jsonutils.QueryBoolean(query, "override_pending_delete", false)
|
||||
purge = jsonutils.QueryBoolean(query, "purge", false)
|
||||
}
|
||||
return self.StartDeleteGuestTask(ctx, userCred, "", purge, overridePendingDelete)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ func (self *GuestRebuildRootTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
}
|
||||
}
|
||||
|
||||
func (self *GuestRebuildRootTask) OnStopServerComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
self.StartRebuildRootDisk(ctx, guest)
|
||||
}
|
||||
|
||||
func (self *GuestRebuildRootTask) StartRebuildRootDisk(ctx context.Context, guest *models.SGuest) {
|
||||
db.OpsLog.LogEvent(guest, db.ACT_REBUILDING_ROOT, nil, self.UserCred)
|
||||
gds := guest.CategorizeDisks()
|
||||
|
||||
Reference in New Issue
Block a user