@@ -42,6 +42,7 @@ import (
4242 "github.com/AliceO2Group/Control/common/system"
4343 "github.com/AliceO2Group/Control/common/utils"
4444 "github.com/AliceO2Group/Control/common/utils/uid"
45+ lhcevent "github.com/AliceO2Group/Control/core/integration/lhc/event"
4546 event2 "github.com/AliceO2Group/Control/core/integration/odc/event"
4647 "github.com/AliceO2Group/Control/core/task"
4748 "github.com/AliceO2Group/Control/core/task/sm"
@@ -1065,6 +1066,61 @@ func (envs *Manager) handleIntegratedServiceEvent(evt event.IntegratedServiceEve
10651066 }
10661067 }
10671068 }
1069+ } else if evt .GetServiceName () == "LHC" {
1070+ envs .handleLhcEvents (evt )
1071+ }
1072+ }
1073+
1074+ func (envs * Manager ) handleLhcEvents (evt event.IntegratedServiceEvent ) {
1075+
1076+ lhcEvent , ok := evt .(* lhcevent.LhcStateChangeEvent )
1077+ if ! ok {
1078+ return
1079+ }
1080+
1081+ // stop all relevant environments when beams are dumped
1082+ beamMode := lhcEvent .GetBeamInfo ().BeamMode
1083+ beamsDumped := beamMode == evpb .BeamMode_BEAM_DUMP || beamMode == evpb .BeamMode_LOST_BEAMS || beamMode == evpb .BeamMode_NO_BEAM
1084+ if ! beamsDumped {
1085+ return
1086+ }
1087+
1088+ for envId , env := range envs .m {
1089+ if env .GetKV ("" , "stop_at_beam_dump" ) == "true" && env .CurrentState () == "RUNNING" {
1090+ if currentTransition := env .CurrentTransition (); currentTransition != "" {
1091+ log .WithPrefix ("scheduler" ).
1092+ WithField (infologger .Level , infologger .IL_Support ).
1093+ WithField ("partition" , envId .String ()).
1094+ Infof ("run was supposed to be stopped at beam dump, but transition '%s' is already in progress, skipping (probably the operator was faster)" , currentTransition )
1095+ continue
1096+ }
1097+
1098+ go func (env * Environment ) {
1099+ log .WithPrefix ("scheduler" ).
1100+ WithField (infologger .Level , infologger .IL_Ops ).
1101+ WithField ("partition" , envId .String ()).
1102+ Info ("stopping the run due to beam dump" )
1103+
1104+ err := env .TryTransition (NewStopActivityTransition (envs .taskman ))
1105+ if err != nil {
1106+ log .WithPrefix ("scheduler" ).
1107+ WithField ("partition" , envId .String ()).
1108+ WithError (err ).
1109+ Error ("could not stop the run upon beam dump" )
1110+
1111+ if env .CurrentState () != "ERROR" {
1112+ err = env .TryTransition (NewGoErrorTransition (envs .taskman ))
1113+ if err != nil {
1114+ log .WithPrefix ("scheduler" ).
1115+ WithField ("partition" , envId .String ()).
1116+ WithError (err ).
1117+ Error ("environment GO_ERROR transition failed after a beam dump event, forcing" )
1118+ env .setState ("ERROR" )
1119+ }
1120+ }
1121+ }
1122+ }(env )
1123+ }
10681124 }
10691125}
10701126
0 commit comments