MCPcopy
hub / github.com/yusing/godoxy / stopByMethod

Method stopByMethod

internal/idlewatcher/watcher.go:497–540  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

495}
496
497func (w *Watcher) stopByMethod() error {
498 // no need singleflight here because it will only be called once every tick.
499
500 // if the container is not running, skip and stop dependencies.
501 if !w.running() {
502 if err := w.stopDependencies(); err != nil {
503 return w.newWatcherError(err)
504 }
505 return nil
506 }
507
508 cfg := w.cfg
509 ctx, cancel := context.WithTimeout(context.Background(), cfg.StopTimeout)
510 defer cancel()
511
512 // stop itself first.
513 var err error
514 p := w.provider.Load()
515 if p == nil {
516 return errors.New("provider not set")
517 }
518 switch cfg.StopMethod {
519 case types.ContainerStopMethodPause:
520 err = p.ContainerPause(ctx)
521 case types.ContainerStopMethodStop:
522 err = p.ContainerStop(ctx, cfg.StopSignal, int(math.Ceil(cfg.StopTimeout.Seconds())))
523 case types.ContainerStopMethodKill:
524 err = p.ContainerKill(ctx, cfg.StopSignal)
525 default:
526 err = w.newWatcherError(fmt.Errorf("unexpected stop method: %q", cfg.StopMethod))
527 }
528
529 if err != nil {
530 return w.newWatcherError(err)
531 }
532
533 w.l.Info().Msg("container stopped")
534
535 // then stop dependencies.
536 if err := w.stopDependencies(); err != nil {
537 return w.newWatcherError(err)
538 }
539 return nil
540}
541
542func (w *Watcher) resetIdleTimer() {
543 w.idleTicker.Reset(w.cfg.IdleTimeout)

Callers 1

watchUntilDestroyMethod · 0.95

Calls 8

runningMethod · 0.95
stopDependenciesMethod · 0.95
newWatcherErrorMethod · 0.95
LoadMethod · 0.80
NewMethod · 0.80
ContainerPauseMethod · 0.65
ContainerStopMethod · 0.65
ContainerKillMethod · 0.65

Tested by

no test coverage detected