【修改第三方服务报错后没有销毁问题】

This commit is contained in:
weizhihong 2023-10-27 17:23:44 +08:00
parent cc99be478f
commit c7f1137e59
4 changed files with 7 additions and 21 deletions

View File

@ -21,20 +21,16 @@ func NewSimulationStateMs(vs *memory.VerifySimulation) *SimulationStateMs {
vs: vs,
channel: fmt.Sprintf("simulation-%s-status", vs.SimulationId),
}
go stateListen(ms)
return ms
}
func stateListen(ms *SimulationStateMs) {
ecs.WorldStateChangeEvent.Subscribe(ms.vs.World, func(_ ecs.World, e ecs.WorldStateChange) {
switch e.NewState {
case ecs.WorldClose:
doSendState(ms.channel, &state.SimulationStatus{
SimulationId: ms.vs.SimulationId,
SimulationId: vs.SimulationId,
State: state.SimulationStatus_DESTROY,
})
}
})
return ms
}
func doSendState(channel string, status *state.SimulationStatus) error {

View File

@ -184,7 +184,8 @@ func (d *dynamics) Start(manager DynamicsMessageManager) error {
// 初始化运行资源
err := d.initDynamicsRunRepository()
if err != nil {
panic("启动动力学消息服务错误: 存在正在运行的任务")
d.Stop() // 发送错误后将信息销毁
panic(err)
}
ctx, cancle := context.WithCancel(context.Background())
go d.sendTurnoutStateTask(ctx)
@ -228,8 +229,8 @@ func (d *dynamics) Stop() {
}
if d.turnoutTaskCancel != nil {
d.turnoutTaskCancel()
d.manager = nil
}
d.manager = nil
}
const (

View File

@ -117,8 +117,8 @@ func (i *interlockProxy) Stop() {
}
if i.collectInfoTaskCancel != nil {
i.collectInfoTaskCancel()
i.manager = nil
}
i.manager = nil
}
func (i *interlockProxy) SendCollectMessage(b []byte) {

View File

@ -225,10 +225,6 @@ func convert(info *message.DynamicsTrainInfo, sta *state.TrainState, simulation
// 获取动力学配置信息
func (s *VerifySimulation) GetDynamicsRunConfig() *config.DynamicsConfig {
// TODO:目前为了兼容当前配置方式做成查询方式后删除IP判断
if config.Config.Dynamics.Ip != "" {
return &config.Config.Dynamics
}
return &s.runConfig.Dynamics
}
@ -327,10 +323,6 @@ func (s *VerifySimulation) HandleSemiPhysicalTrainControlMsg(b []byte) {
// 获取半实物运行配置信息
func (s *VerifySimulation) GetSemiPhysicalRunConfig() *config.VobcConfig {
// TODO:目前为了兼容当前配置方式做成查询方式后删除IP判断
if config.Config.Vobc.Ip != "" {
return &config.Config.Vobc
}
return &s.runConfig.Vobc
}
@ -348,15 +340,12 @@ func (s *VerifySimulation) HandleDriverInfo(b []byte) {
// 获取联锁配置
func (s *VerifySimulation) GetInterlockRunConfig() *config.InterlockConfig {
// TODO:目前为了兼容当前配置方式做成查询方式后删除IP判断
if config.Config.Interlock.Ip != "" {
return &config.Config.Interlock
}
return &s.runConfig.Interlock
}
// 采集联锁中的继电器消息
func (s *VerifySimulation) CollectRelayInfo() []*message.InterlockSendMsgPkg {
msg := &message.InterlockSendMsgPkg{}
relayArr := make([]string, 256)
for index, id := range relayArr {