CertWorker is the actual worker routine that eats away from the queue
(id int, client api.CertificateIssuerClient, storage *CertStorage)
| 43 | |
| 44 | // CertWorker is the actual worker routine that eats away from the queue |
| 45 | func CertWorker(id int, client api.CertificateIssuerClient, storage *CertStorage) { |
| 46 | var prefix = fmt.Sprintf("[worker-%d]", id) |
| 47 | for job := range JobQueue { |
| 48 | |
| 49 | if job.Attempts >= 5 { |
| 50 | log.Warnf("%s Attempts for %s exceed 5, discarding job", prefix, job.DNSName) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | log.Infof("%s Processing %s", prefix, job.DNSName) |
| 55 | |
| 56 | res, err := client.IssueCert(context.TODO(), &api.CertificateRequest{DnsName: job.DNSName}) |
| 57 | |
| 58 | if err != nil { |
| 59 | log.Warnf("%s Encountered error while requesting certs for %s: %v", prefix, job.DNSName, err) |
| 60 | job.Attempts++ |
| 61 | log.Warnf("%s Increasing attempt counter to %d and re-queuing...", prefix, job.Attempts) |
| 62 | JobQueue <- job |
| 63 | } else { |
| 64 | log.Infof("%s Successfully fetched certs for %s", prefix, job.DNSName) |
| 65 | err := storage.Store(job.DNSName, res) |
| 66 | |
| 67 | if err != nil { |
| 68 | log.Warnf("Could not write cert data for %s: %v", job.DNSName, err) |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
no test coverage detected