forked from TrueCloudLab/lego
Order polling wait (#581)
This commit is contained in:
parent
05921d9810
commit
54422ab226
1 changed files with 22 additions and 17 deletions
|
@ -708,26 +708,31 @@ 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()
|
||||||
|
retryTick := time.NewTicker(500 * time.Millisecond)
|
||||||
|
defer retryTick.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-stopTimer.C:
|
||||||
|
return nil, errors.New("certificate polling timed out")
|
||||||
|
case <-retryTick.C:
|
||||||
_, err := getJSON(order.URL, &retOrder)
|
_, err := getJSON(order.URL, &retOrder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
done, err := c.checkCertResponse(retOrder, &certRes, bundle)
|
done, err := c.checkCertResponse(retOrder, &certRes, bundle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if done {
|
if done {
|
||||||
break
|
|
||||||
}
|
|
||||||
if i == maxChecks-1 {
|
|
||||||
return nil, fmt.Errorf("polled for certificate %d times; giving up", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
// response. if so, loads it into certRes and returns true. If the cert
|
// response. if so, loads it into certRes and returns true. If the cert
|
||||||
|
|
Loading…
Reference in a new issue