Order polling wait (#581)

This commit is contained in:
Robert Kästel 2018-06-25 23:22:42 +02:00 committed by Ludovic Fernandez
parent 05921d9810
commit 54422ab226

View file

@ -708,25 +708,30 @@ func (c *Client) requestCertificateForCsr(order orderResource, bundle bool, csr
} }
} }
maxChecks := 1000 stopTimer := time.NewTimer(30 * time.Second)
for i := 0; i < maxChecks; i++ { defer stopTimer.Stop()
_, err := getJSON(order.URL, &retOrder) retryTick := time.NewTicker(500 * time.Millisecond)
if err != nil { defer retryTick.Stop()
return nil, err
} for {
done, err := c.checkCertResponse(retOrder, &certRes, bundle) select {
if err != nil { case <-stopTimer.C:
return nil, err return nil, errors.New("certificate polling timed out")
} case <-retryTick.C:
if done { _, err := getJSON(order.URL, &retOrder)
break if err != nil {
} return nil, err
if i == maxChecks-1 { }
return nil, fmt.Errorf("polled for certificate %d times; giving up", i)
done, err := c.checkCertResponse(retOrder, &certRes, bundle)
if err != nil {
return nil, err
}
if done {
return &certRes, nil
}
} }
} }
return &certRes, nil
} }
// checkCertResponse checks to see if the certificate is ready and a link is contained in the // checkCertResponse checks to see if the certificate is ready and a link is contained in the