Shutdown gracefully exists with the option to cancel the active job. If false, it will wait for the job to complete. nolint:revive
(ctx context.Context, cancelActiveJob bool)
| 642 | // |
| 643 | //nolint:revive |
| 644 | func (p *Server) Shutdown(ctx context.Context, cancelActiveJob bool) error { |
| 645 | p.mutex.Lock() |
| 646 | p.opts.Logger.Info(ctx, "attempting graceful shutdown") |
| 647 | if !p.shuttingDownB { |
| 648 | close(p.shuttingDownCh) |
| 649 | p.shuttingDownB = true |
| 650 | } |
| 651 | if cancelActiveJob && p.activeJob != nil { |
| 652 | p.activeJob.Cancel() |
| 653 | } |
| 654 | p.mutex.Unlock() |
| 655 | select { |
| 656 | case <-ctx.Done(): |
| 657 | p.opts.Logger.Warn(ctx, "graceful shutdown failed", slog.Error(ctx.Err())) |
| 658 | return ctx.Err() |
| 659 | case <-p.acquireDoneCh: |
| 660 | p.opts.Logger.Info(ctx, "gracefully shutdown") |
| 661 | return nil |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | // Close ends the provisioner. It will mark any running jobs as failed. |
| 666 | func (p *Server) Close() error { |