mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-03-12 04:55:38 +08:00
fix: 移除隧道连接时检测是否正在使用
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"mayfly-go/internal/es/domain/repository"
|
||||
"mayfly-go/internal/es/esm/esi"
|
||||
"mayfly-go/internal/es/imsg"
|
||||
"mayfly-go/internal/machine/mcm"
|
||||
"mayfly-go/internal/pkg/consts"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagdto "mayfly-go/internal/tag/application/dto"
|
||||
@@ -40,6 +41,25 @@ var _ Instance = &instanceAppImpl{}
|
||||
|
||||
var poolGroup = pool.NewPoolGroup[*esi.EsConn]()
|
||||
|
||||
func init() {
|
||||
mcm.AddCheckSshTunnelMachineUseFunc(func(machineId int) bool {
|
||||
items := poolGroup.AllPool()
|
||||
for _, v := range items {
|
||||
if v.Stats().TotalConns == 0 {
|
||||
continue // 连接池中没有连接,跳过
|
||||
}
|
||||
conn, err := v.Get(context.Background())
|
||||
if err != nil {
|
||||
continue // 获取连接失败,跳过
|
||||
}
|
||||
if conn.Info.SshTunnelMachineId == machineId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
type instanceAppImpl struct {
|
||||
base.AppImpl[*entity.EsInstance, repository.EsInstance]
|
||||
|
||||
@@ -234,6 +254,8 @@ func (app *instanceAppImpl) Delete(ctx context.Context, instanceId uint64) error
|
||||
return errorx.NewBiz("db instnace not found")
|
||||
}
|
||||
|
||||
poolGroup.Close(fmt.Sprintf("es-%d", instanceId))
|
||||
|
||||
return app.Tx(ctx, func(ctx context.Context) error {
|
||||
// 删除该实例
|
||||
return app.DeleteById(ctx, instanceId)
|
||||
|
||||
Reference in New Issue
Block a user