mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 18:16:26 +00:00
Moved v3 code from NginxProxyManager/nginx-proxy-manager-3 to NginxProxyManager/nginx-proxy-manager
This commit is contained in:
63
backend/internal/worker/certificate.go
Normal file
63
backend/internal/worker/certificate.go
Normal file
@ -0,0 +1,63 @@
|
||||
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:
|
||||
// Can confirm that this will wait for completion before the next loop
|
||||
requestCertificates()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func requestCertificates() {
|
||||
// logger.Debug("requestCertificates fired")
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user