feat(cert): skip non-success status in auto-renew worker

This commit is contained in:
Hintay
2026-05-23 04:52:55 +09:00
parent 77bf8f8a07
commit 43d83f49a9
2 changed files with 37 additions and 0 deletions
+16
View File
@@ -42,6 +42,11 @@ func autoCert(certModel *model.Cert) {
targetName := getAutoRenewTargetName(certModel)
now := time.Now()
if shouldSkipAutoCertByStatus(certModel) {
logger.Infof("Skip auto cert for %s due to status %s", targetName, certModel.Status)
return
}
if shouldSkipAutoRenew(certModel, now) {
logger.Infof("Skip auto renew for %s until %s after previous failure", targetName,
certModel.LastAutoRenewAt.Add(autoRenewFailureRetryCooldown).Format(time.DateTime))
@@ -145,6 +150,17 @@ func shouldSkipAutoRenew(certModel *model.Cert, now time.Time) bool {
return now.Before(certModel.LastAutoRenewAt.Add(autoRenewFailureRetryCooldown))
}
// shouldSkipAutoCertByStatus returns true when the cert's most recent
// issuance attempt has not succeeded. Pending and failed certs must
// be retried by the user explicitly; auto-renew should not touch them.
func shouldSkipAutoCertByStatus(certModel *model.Cert) bool {
if certModel == nil {
return false
}
return certModel.Status == model.CertStatusPending ||
certModel.Status == model.CertStatusFailure
}
func handleAutoRenewFailure(certModel *model.Cert, log *Logger, name string, err error) {
log.Error(err)
updateAutoRenewStatus(certModel, time.Now(), err.Error())
+21
View File
@@ -98,3 +98,24 @@ func TestGetAutoRenewNotificationResponseFallsBackToPlainText(t *testing.T) {
t.Fatalf("unexpected fallback response: %s", text)
}
}
func TestShouldSkipAutoCertForNonSuccessStatus(t *testing.T) {
cases := []struct {
name string
status string
expected bool
}{
{"pending is skipped", model.CertStatusPending, true},
{"failure is skipped", model.CertStatusFailure, true},
{"success is renewed", model.CertStatusSuccess, false},
{"empty (legacy) is renewed", "", false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
cert := &model.Cert{Status: tc.status}
if got := shouldSkipAutoCertByStatus(cert); got != tc.expected {
t.Fatalf("shouldSkipAutoCertByStatus(%q) = %v, want %v", tc.status, got, tc.expected)
}
})
}
}