mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(glance): avoid context warnning (#24074)
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
type domainCacheSyncWorker struct {
|
||||
@@ -35,7 +36,7 @@ type domainCacheSyncWorker struct {
|
||||
|
||||
func (w *domainCacheSyncWorker) Run() {
|
||||
log.Debugf("[domainCacheSyncWorker] Run domain cache sync worker ...")
|
||||
err := syncDomains(context.Background(), w.ids)
|
||||
err := syncDomains(ctx.CtxWithTime(), w.ids)
|
||||
if err != nil {
|
||||
log.Errorf("fail to syncDomains %s", err)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
@@ -199,7 +200,7 @@ func (manager *SOpsLogManager) LogEvent(model IModel, action string, notes inter
|
||||
}
|
||||
|
||||
func (opslog *SOpsLog) Run() {
|
||||
err := OpsLog.TableSpec().Insert(context.Background(), opslog)
|
||||
err := OpsLog.TableSpec().Insert(ctx.CtxWithTime(), opslog)
|
||||
if err != nil {
|
||||
log.Errorf("fail to insert opslog: %s", err)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
type SProxySettingManager struct {
|
||||
@@ -224,7 +225,7 @@ func (man *SProxySettingManager) InitializeData() error {
|
||||
ps.Description = "Connect directly"
|
||||
ps.IsPublic = true
|
||||
ps.PublicScope = string(rbacscope.ScopeSystem)
|
||||
if err := man.TableSpec().Insert(context.Background(), ps); err != nil {
|
||||
if err := man.TableSpec().Insert(ctx.CtxWithTime(), ps); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
identityapi "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
type SQuotaBaseManager struct {
|
||||
@@ -284,7 +285,7 @@ func (manager *SQuotaBaseManager) InitializeData() error {
|
||||
if !reflectutils.FillEmbededStructValue(reflect.Indirect(reflect.ValueOf(quota)), reflect.ValueOf(baseKeys)) {
|
||||
log.Fatalf("invalid quota??? fail to find SBaseQuotaKey")
|
||||
}
|
||||
err := metaQuota.GetQuota(context.Background(), scope, ownerId, quota)
|
||||
err := metaQuota.GetQuota(ctx.CtxWithTime(), scope, ownerId, quota)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
log.Errorf("metaQuota.GetQuota error %s for %s", err, ownerId)
|
||||
continue
|
||||
@@ -292,7 +293,7 @@ func (manager *SQuotaBaseManager) InitializeData() error {
|
||||
if quota.IsEmpty() {
|
||||
quota.FetchSystemQuota()
|
||||
}
|
||||
err = manager.TableSpec().Insert(context.Background(), quota)
|
||||
err = manager.TableSpec().Insert(ctx.CtxWithTime(), quota)
|
||||
if err != nil {
|
||||
log.Errorf("%s insert error %s", manager.KeywordPlural(), err)
|
||||
continue
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,7 +70,7 @@ type quotaTask struct {
|
||||
}
|
||||
|
||||
func (t *quotaTask) Run() {
|
||||
ctx := context.WithValue(context.Background(), "task", t)
|
||||
ctx := context.WithValue(ctx.CtxWithTime(), "task", t)
|
||||
|
||||
usage := t.manager.newQuota()
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package taskman
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
@@ -28,6 +27,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
var localTaskWorkerMan *appsrv.SWorkerManager
|
||||
@@ -52,7 +52,7 @@ type localTask struct {
|
||||
func (t *localTask) Run() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
yunionconf.BugReport.SendBugReport(context.Background(), version.GetShortString(), string(debug.Stack()), errors.Errorf("%s", r))
|
||||
yunionconf.BugReport.SendBugReport(ctx.CtxWithTime(), version.GetShortString(), string(debug.Stack()), errors.Errorf("%s", r))
|
||||
log.Errorf("LocalTaskRun error: %s", r)
|
||||
debug.PrintStack()
|
||||
t.task.ScheduleRun(Error2TaskData(fmt.Errorf("LocalTaskRun error: %s stack: %s", r, string(debug.Stack()))))
|
||||
|
||||
@@ -50,6 +50,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
@@ -1440,7 +1441,7 @@ func (manager *STaskManager) migrateObjectInfo() error {
|
||||
taskObj.ProjectId = task.ProjectId
|
||||
taskObj.SetModelManager(TaskObjectManager, &taskObj)
|
||||
|
||||
err = TaskObjectManager.TableSpec().Insert(context.Background(), &taskObj)
|
||||
err = TaskObjectManager.TableSpec().Insert(ctx.CtxWithTime(), &taskObj)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Insert taskObject")
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/util/ctx"
|
||||
)
|
||||
|
||||
func Update(model IModel, updateFunc func() error) (sqlchemy.UpdateDiffs, error) {
|
||||
return model.GetModelManager().TableSpec().Update(context.Background(), model, updateFunc)
|
||||
return model.GetModelManager().TableSpec().Update(ctx.CtxWithTime(), model, updateFunc)
|
||||
}
|
||||
|
||||
func UpdateWithLock(ctx context.Context, model IModel, updateFunc func() error) (sqlchemy.UpdateDiffs, error) {
|
||||
|
||||
@@ -870,8 +870,7 @@ func (self *SImage) StartImageCheckTask(ctx context.Context, userCred mcclient.T
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SImage) StartPutImageTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
@@ -879,8 +878,7 @@ func (self *SImage) StartPutImageTask(ctx context.Context, userCred mcclient.Tok
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
return task.ScheduleRun(nil)
|
||||
}
|
||||
|
||||
func (self *SImage) PerformCancelDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
@@ -1262,8 +1260,7 @@ func (manager *SImageManager) getAllAliveImages() []SImage {
|
||||
return images
|
||||
}
|
||||
|
||||
func CheckImages() {
|
||||
ctx := context.WithValue(context.TODO(), "checkimage", 1)
|
||||
func CheckImages(ctx context.Context) {
|
||||
images := ImageManager.getAllAliveImages()
|
||||
for i := 0; i < len(images); i += 1 {
|
||||
log.Debugf("convert image subformats %s", images[i].Name)
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
_ "yunion.io/x/sqlchemy/backends"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/image"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon"
|
||||
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/cronman"
|
||||
@@ -130,7 +131,7 @@ func StartService() {
|
||||
}
|
||||
|
||||
if !opts.IsSlaveNode {
|
||||
startMasterTasks(opts)
|
||||
startMasterTasks(app, opts)
|
||||
}
|
||||
|
||||
app_common.ServeForeverWithCleanup(app, baseOpts, func() {
|
||||
@@ -147,7 +148,7 @@ func StartService() {
|
||||
})
|
||||
}
|
||||
|
||||
func startMasterTasks(opts *options.SImageOptions) {
|
||||
func startMasterTasks(app *appsrv.Application, opts *options.SImageOptions) {
|
||||
log.Infof("Target image formats %#v", opts.TargetImageFormats)
|
||||
|
||||
if ok, err := hasVmwareAccount(); err != nil {
|
||||
@@ -167,7 +168,7 @@ func startMasterTasks(opts *options.SImageOptions) {
|
||||
initS3()
|
||||
}
|
||||
// check image after s3 mounted
|
||||
models.CheckImages()
|
||||
models.CheckImages(app.GetContext())
|
||||
}()
|
||||
|
||||
err := taskman.TaskManager.InitializeData()
|
||||
|
||||
Reference in New Issue
Block a user