fix: save plugin db is locked (#2080)
Some checks failed
commit-ci-build / rainbond (api) (push) Has been cancelled
commit-ci-build / rainbond (chaos) (push) Has been cancelled
commit-ci-build / rainbond (init-probe) (push) Has been cancelled
commit-ci-build / rainbond (mq) (push) Has been cancelled
commit-ci-build / rainbond (worker) (push) Has been cancelled
Commit Message Check / Check Commit Message (push) Has been cancelled

Signed-off-by: 张启航 <101104760+ZhangSetSail@users.noreply.github.com>
This commit is contained in:
张启航 2024-11-27 11:11:57 +08:00 committed by GitHub
parent 2e5b5cd4bb
commit 73fe67a4c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -145,7 +145,7 @@ func (s *ServiceAction) SetTenantServicePluginRelation(tenantID, serviceID strin
p.ListenPort = pluginPort
}
}
if err := s.SavePluginConfig(serviceID, plugin.PluginID, pss.Body.ConfigEnvs.ComplexEnvs); err != nil {
if err := s.SavePluginConfig(serviceID, plugin.PluginID, pss.Body.ConfigEnvs.ComplexEnvs, tx); err != nil {
tx.Rollback()
return nil, util.CreateAPIHandleError(500, fmt.Errorf("set complex error, %v", err))
}
@ -261,7 +261,7 @@ func (s *ServiceAction) UpdateVersionEnv(uve *apimodel.SetVersionEnv) *util.APIH
p.ListenPort = pluginPort
}
}
if err := s.SavePluginConfig(uve.Body.ServiceID, uve.PluginID, uve.Body.ConfigEnvs.ComplexEnvs); err != nil {
if err := s.SavePluginConfig(uve.Body.ServiceID, uve.PluginID, uve.Body.ConfigEnvs.ComplexEnvs, tx); err != nil {
tx.Rollback()
return util.CreateAPIHandleError(500, fmt.Errorf("update complex error, %v", err))
}
@ -291,7 +291,7 @@ func (s *ServiceAction) upNormalEnvs(tx *gorm.DB, uve *apimodel.SetVersionEnv) *
}
// SavePluginConfig save plugin dynamic discovery config
func (s *ServiceAction) SavePluginConfig(serviceID, pluginID string, config *apimodel.ResourceSpec) *util.APIHandleError {
func (s *ServiceAction) SavePluginConfig(serviceID, pluginID string, config *apimodel.ResourceSpec, tx *gorm.DB) *util.APIHandleError {
if config == nil {
return nil
}
@ -300,7 +300,7 @@ func (s *ServiceAction) SavePluginConfig(serviceID, pluginID string, config *api
logrus.Errorf("mashal plugin config value error, %v", err)
return util.CreateAPIHandleError(500, err)
}
if err := db.GetManager().TenantPluginVersionConfigDao().AddModel(&dbmodel.TenantPluginVersionDiscoverConfig{
if err := db.GetManager().TenantPluginVersionConfigDaoTransactions(tx).AddModel(&dbmodel.TenantPluginVersionDiscoverConfig{
PluginID: pluginID,
ServiceID: serviceID,
ConfigStr: string(v),