acquireGraceful attempts to acquire a job from the server, handling canceling the acquisition if we gracefully shut down.
(client proto.DRPCProvisionerDaemonClient)
| 439 | // acquireGraceful attempts to acquire a job from the server, handling canceling the acquisition if we gracefully shut |
| 440 | // down. |
| 441 | func (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 | |
| 467 | func retryable(err error) bool { |
| 468 | return xerrors.Is(err, yamux.ErrSessionShutdown) || xerrors.Is(err, io.EOF) || xerrors.Is(err, fasthttputil.ErrInmemoryListenerClosed) || |
no test coverage detected