MCPcopy Index your code
hub / github.com/coder/coder / acquireGraceful

Method acquireGraceful

provisionerd/provisionerd.go:441–465  ·  view source on GitHub ↗

acquireGraceful attempts to acquire a job from the server, handling canceling the acquisition if we gracefully shut down.

(client proto.DRPCProvisionerDaemonClient)

Source from the content-addressed store, hash-verified

439// acquireGraceful attempts to acquire a job from the server, handling canceling the acquisition if we gracefully shut
440// down.
441func (p *Server) acquireGraceful(client proto.DRPCProvisionerDaemonClient) (*proto.AcquiredJob, error) {
442 stream, err := client.AcquireJobWithCancel(p.closeContext)
443 if err != nil {
444 return nil, err
445 }
446 acquireDone := make(chan struct{})
447 go func() {
448 select {
449 case <-p.closeContext.Done():
450 return
451 case <-p.shuttingDownCh:
452 p.opts.Logger.Debug(p.closeContext, "sending acquire job cancel")
453 err := stream.Send(&proto.CancelAcquire{})
454 if err != nil {
455 p.opts.Logger.Warn(p.closeContext, "failed to gracefully cancel acquire job")
456 }
457 return
458 case <-acquireDone:
459 return
460 }
461 }()
462 job, err := stream.Recv()
463 close(acquireDone)
464 return job, err
465}
466
467func retryable(err error) bool {
468 return xerrors.Is(err, yamux.ErrSessionShutdown) || xerrors.Is(err, io.EOF) || xerrors.Is(err, fasthttputil.ErrInmemoryListenerClosed) ||

Callers 1

acquireAndRunOneMethod · 0.95

Calls 4

AcquireJobWithCancelMethod · 0.65
SendMethod · 0.65
RecvMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected