@@ -237,21 +237,25 @@ func (s *composeService) removeVolume(ctx context.Context, id string, w progress
237
237
return err
238
238
}
239
239
240
+ func (s * composeService ) stopContainer (ctx context.Context , w progress.Writer , container moby.Container , timeout * time.Duration ) error {
241
+ eventName := getContainerProgressName (container )
242
+ w .Event (progress .StoppingEvent (eventName ))
243
+ timeoutInSecond := utils .DurationSecondToInt (timeout )
244
+ err := s .apiClient ().ContainerStop (ctx , container .ID , containerType.StopOptions {Timeout : timeoutInSecond })
245
+ if err != nil {
246
+ w .Event (progress .ErrorMessageEvent (eventName , "Error while Stopping" ))
247
+ return err
248
+ }
249
+ w .Event (progress .StoppedEvent (eventName ))
250
+ return nil
251
+ }
252
+
240
253
func (s * composeService ) stopContainers (ctx context.Context , w progress.Writer , containers []moby.Container , timeout * time.Duration ) error {
241
254
eg , ctx := errgroup .WithContext (ctx )
242
255
for _ , container := range containers {
243
256
container := container
244
257
eg .Go (func () error {
245
- eventName := getContainerProgressName (container )
246
- w .Event (progress .StoppingEvent (eventName ))
247
- timeoutInSecond := utils .DurationSecondToInt (timeout )
248
- err := s .apiClient ().ContainerStop (ctx , container .ID , containerType.StopOptions {Timeout : timeoutInSecond })
249
- if err != nil {
250
- w .Event (progress .ErrorMessageEvent (eventName , "Error while Stopping" ))
251
- return err
252
- }
253
- w .Event (progress .StoppedEvent (eventName ))
254
- return nil
258
+ return s .stopContainer (ctx , w , container , timeout )
255
259
})
256
260
}
257
261
return eg .Wait ()
@@ -263,10 +267,8 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
263
267
container := container
264
268
eg .Go (func () error {
265
269
eventName := getContainerProgressName (container )
266
- w .Event (progress .StoppingEvent (eventName ))
267
- err := s .stopContainers (ctx , w , []moby.Container {container }, timeout )
270
+ err := s .stopContainer (ctx , w , container , timeout )
268
271
if err != nil {
269
- w .Event (progress .ErrorMessageEvent (eventName , "Error while Stopping" ))
270
272
return err
271
273
}
272
274
w .Event (progress .RemovingEvent (eventName ))
0 commit comments