mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56:37 +08:00
[优化] go 引用调整
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package job
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/rain-kl/openflare/openflare-server/model"
|
||||
"github.com/rain-kl/openflare/openflare-server/service"
|
||||
)
|
||||
|
||||
type SSLRenewJob struct {
|
||||
}
|
||||
|
||||
func (j *SSLRenewJob) Run() {
|
||||
slog.Info("The scheduled certificate update task is currently in progress ...")
|
||||
|
||||
certificates, err := model.ListTLSCertificates()
|
||||
if err != nil {
|
||||
slog.Error("failed to list certificates in SSL renew job", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for _, cert := range certificates {
|
||||
if !cert.AutoRenew || cert.Provider != "acme" || cert.ApplyStatus == "applying" {
|
||||
continue
|
||||
}
|
||||
|
||||
sub := cert.NotAfter.Sub(now)
|
||||
// Expiring in less than 7 days (7 * 24 hours)
|
||||
if sub.Hours() < 168 {
|
||||
slog.Info("Update the SSL certificate for the domain", "domain", cert.PrimaryDomain)
|
||||
|
||||
// Invoke renew process (async go-routine handles Lego inside)
|
||||
_, err := service.RenewTLSCertificate(cert.ID)
|
||||
if err != nil {
|
||||
slog.Error("Failed to update the SSL certificate", "domain", cert.PrimaryDomain, "error", err)
|
||||
continue
|
||||
}
|
||||
slog.Info("Triggered the SSL certificate renew for domain", "domain", cert.PrimaryDomain)
|
||||
}
|
||||
}
|
||||
slog.Info("The scheduled certificate update task has completed")
|
||||
}
|
||||
Reference in New Issue
Block a user