@@ -299,6 +299,24 @@ func (m *RpcServer) DestroyEnvironment(cxt context.Context, req *pb.DestroyEnvir
299299 return nil , status .Newf (codes .NotFound , "environment not found: %s" , err .Error ()).Err ()
300300 }
301301
302+ // if Force immediately disband the environment (unlocking all tasks) and run the cleanup.
303+ if req .Force {
304+ err = m .state .environments .TeardownEnvironment (env .Id (), req .Force )
305+ if err != nil {
306+ return & pb.DestroyEnvironmentReply {}, status .New (codes .Internal , err .Error ()).Err ()
307+ }
308+
309+ tasksForEnv := env .Workflow ().GetTasks ().GetTaskIds ()
310+ killed , running , err := m .doCleanupTasks (tasksForEnv )
311+ ctr := & pb.CleanupTasksReply {KilledTasks : killed , RunningTasks : running }
312+ if err != nil {
313+ log .WithError (err ).Error ("task cleanup error" )
314+ return & pb.DestroyEnvironmentReply {CleanupTasksReply : ctr }, status .New (codes .Internal , err .Error ()).Err ()
315+ }
316+
317+ return & pb.DestroyEnvironmentReply {CleanupTasksReply : ctr }, nil
318+ }
319+
302320 if req .AllowInRunningState && env .CurrentState () == "RUNNING" {
303321 err = env .TryTransition (environment .MakeTransition (m .state .taskman , pb .ControlEnvironmentRequest_STOP_ACTIVITY ))
304322 if err != nil {
@@ -328,7 +346,7 @@ func (m *RpcServer) DestroyEnvironment(cxt context.Context, req *pb.DestroyEnvir
328346 }
329347 }
330348
331- err = m .state .environments .TeardownEnvironment (env .Id ())
349+ err = m .state .environments .TeardownEnvironment (env .Id (), req . Force )
332350 if err != nil {
333351 return & pb.DestroyEnvironmentReply {}, status .New (codes .Internal , err .Error ()).Err ()
334352 }
0 commit comments