@@ -718,10 +718,18 @@ func (m *RpcServer) DestroyEnvironment(cxt context.Context, req *pb.DestroyEnvir
718718 }
719719
720720 if req .AllowInRunningState && env .CurrentState () == "RUNNING" {
721- err = env .TryTransition (environment .MakeTransition (m .state .taskman , pb . ControlEnvironmentRequest_STOP_ACTIVITY ))
721+ err = env .TryTransition (environment .NewStopActivityTransition (m .state .taskman ))
722722 if err != nil {
723- log .WithField ("partition" , env .Id ().String ()).
724- Warn ("could not perform STOP transition for environment teardown, forcing" )
723+ log .WithError (err ).
724+ WithField ("partition" , env .Id ().String ()).
725+ Warn ("could not perform STOP transition for environment teardown, going to ERROR, then forcing" )
726+ the .EventWriterWithTopic (topic .Environment ).WriteEvent (
727+ environment .NewEnvGoErrorEvent (env , "STOP_ACTIVITY during environment destruction failed" ),
728+ )
729+ err = env .TryTransition (environment .NewGoErrorTransition (m .state .taskman ))
730+ if err != nil {
731+ environment .HandleFailedGoError (err , env )
732+ }
725733 reply , err = m .doTeardownAndCleanup (env , true /*force*/ , false /*keepTasks*/ )
726734 return
727735 }
@@ -746,10 +754,18 @@ func (m *RpcServer) DestroyEnvironment(cxt context.Context, req *pb.DestroyEnvir
746754
747755 // This might transition to STANDBY if needed, or do nothing if we're already there
748756 if env .CurrentState () == "CONFIGURED" {
749- err = env .TryTransition (environment .MakeTransition (m .state .taskman , pb . ControlEnvironmentRequest_RESET ))
757+ err = env .TryTransition (environment .NewResetTransition (m .state .taskman ))
750758 if err != nil {
751- log .WithField ("partition" , env .Id ().String ()).
752- Warnf ("cannot teardown environment in state %s, forcing" , env .CurrentState ())
759+ log .WithError (err ).
760+ WithField ("partition" , env .Id ().String ()).
761+ Warnf ("cannot teardown environment in state %s, going to ERROR, then forcing" , env .CurrentState ())
762+ the .EventWriterWithTopic (topic .Environment ).WriteEvent (
763+ environment .NewEnvGoErrorEvent (env , "RESET during environment destruction failed" ),
764+ )
765+ err = env .TryTransition (environment .NewGoErrorTransition (m .state .taskman ))
766+ if err != nil {
767+ environment .HandleFailedGoError (err , env )
768+ }
753769 reply , err = m .doTeardownAndCleanup (env , true /*force*/ , false /*keepTasks*/ )
754770 return
755771 }
0 commit comments