Skip to content

Commit

Permalink
fix: save plugin db is locked (#2080)
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail authored Nov 27, 2024
1 parent 2e5b5cd commit 73fe67a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/handler/service_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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),
Expand Down

0 comments on commit 73fe67a

Please sign in to comment.