Version 3 starter

This commit is contained in:
Jamie Curnow
2021-06-14 19:29:35 +10:00
parent 60fc57431a
commit 6205434140
642 changed files with 25817 additions and 32319 deletions

View File

@@ -0,0 +1,61 @@
package worker
import (
"time"
"npm/internal/entity/certificate"
"npm/internal/logger"
"npm/internal/state"
)
type certificateWorker struct {
state *state.AppState
}
// StartCertificateWorker starts the CertificateWorker
func StartCertificateWorker(state *state.AppState) {
worker := newCertificateWorker(state)
logger.Info("CertificateWorker Started")
worker.Run()
}
func newCertificateWorker(state *state.AppState) *certificateWorker {
return &certificateWorker{
state: state,
}
}
// Run the CertificateWorker
func (w *certificateWorker) Run() {
// global wait group
gwg := w.state.GetWaitGroup()
gwg.Add(1)
ticker := time.NewTicker(15 * time.Second)
mainLoop:
for {
select {
case _, more := <-w.state.GetTermSig():
if !more {
logger.Info("Terminating CertificateWorker ... ")
break mainLoop
}
case <-ticker.C:
requestCertificates()
}
}
}
func requestCertificates() {
rows, err := certificate.GetByStatus(certificate.StatusReady)
if err != nil {
logger.Error("requestCertificatesError", err)
return
}
for _, row := range rows {
if err := row.Request(); err != nil {
logger.Error("CertificateRequestError", err)
}
}
}