fix(glance): avoid context warnning (#24075)

This commit is contained in:
屈轩
2026-01-14 10:54:58 +08:00
committed by GitHub
parent 2ba0bdfee7
commit 411a6df9f9
9 changed files with 19 additions and 16 deletions
+2 -1
View File
@@ -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)
}
+2 -1
View File
@@ -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)
}
+2 -1
View File
@@ -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
+3 -2
View File
@@ -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
+2 -1
View File
@@ -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"
@@ -26,6 +25,7 @@ import (
"yunion.io/x/onecloud/pkg/appsrv"
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
"yunion.io/x/onecloud/pkg/util/ctx"
)
var localTaskWorkerMan *appsrv.SWorkerManager
@@ -52,7 +52,7 @@ 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()))))
+2 -1
View File
@@ -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) {
+3 -6
View File
@@ -855,8 +855,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 {
@@ -864,8 +863,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) {
@@ -1245,8 +1243,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)
+1 -1
View File
@@ -144,7 +144,7 @@ func StartService() {
initS3()
}
// check image after s3 mounted
models.CheckImages()
models.CheckImages(app.GetContext())
}()
if !opts.IsSlaveNode {