补齐证书任务并发保护和DNS阶段进度

增加同域名同类活动任务保护、DNS验证阶段进度回调及相关接口冲突响应,补充仓储回归测试。
This commit is contained in:
xuans committed 2026-09-30 03:56:51 +08:00
1 parent 69dc6e10dc
commit 604a1bf4f0
6 files changed
+101 -3

No files matched your search

+18 -3
View File
@@ -103,7 +103,11 @@ func (s *Server) validateCertificate(c *gin.Context) {
if s.validateCertificateWorkflow != nil {
result, validation, err := s.validateCertificateWorkflow(s.taskWorkflowContext(c), strings.TrimSpace(c.Param("id")))
if err != nil {
s.writeError(c, http.StatusUnprocessableEntity, "\u8bc1\u4e66\u6821\u9a8c\u5931\u8d25", err)
status := http.StatusUnprocessableEntity
if errors.Is(err, repository.ErrTaskAlreadyRunning) {
status = http.StatusConflict
}
s.writeError(c, status, "证书校验失败", err)
return
}
c.JSON(http.StatusOK, gin.H{"certificate": result, "validation": validation})
@@ -144,7 +148,11 @@ func (s *Server) deployCertificateCurrent(c *gin.Context) {
s.logger.Error("证书部署失败", "error", err)
}
response["error"] = "证书部署失败"
c.JSON(http.StatusBadGateway, response)
status := http.StatusBadGateway
if errors.Is(err, repository.ErrTaskAlreadyRunning) {
status = http.StatusConflict
}
c.JSON(status, response)
return
}
c.JSON(http.StatusOK, response)
@@ -180,7 +188,11 @@ func (s *Server) importCertificateFiles(c *gin.Context) {
s.logger.Error(message, "error", err)
}
response["error"] = message
c.JSON(http.StatusBadGateway, response)
status := http.StatusBadGateway
if errors.Is(err, repository.ErrTaskAlreadyRunning) {
status = http.StatusConflict
}
c.JSON(status, response)
return
}
c.JSON(http.StatusOK, response)
@@ -287,6 +299,9 @@ func saveOptionalMultipartFile(form *multipart.Form, field string) (string, func
}
func certificateErrorStatus(err error) int {
if errors.Is(err, repository.ErrTaskAlreadyRunning) {
return http.StatusConflict
}
if repository.IsNotFound(err) || errors.Is(err, os.ErrNotExist) {
return http.StatusNotFound
}
+8
View File
@@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"git.pcux.cn/xuans/Scert/backend/internal/certificate"
"git.pcux.cn/xuans/Scert/backend/internal/domain"
"git.pcux.cn/xuans/Scert/backend/internal/repository"
)
@@ -114,6 +115,10 @@ func (s *Server) issueDomainAsTask(c *gin.Context) {
}
}
s.issueTaskMu.Unlock()
if errors.Is(err, repository.ErrTaskAlreadyRunning) {
c.JSON(http.StatusConflict, gin.H{"error": "该域名已有正在执行的同类证书任务"})
return
}
s.writeError(c, http.StatusInternalServerError, "创建证书任务失败", err)
return
}
@@ -167,6 +172,9 @@ func (s *Server) executeCertificateIssueTask(c *gin.Context, task repository.Tas
cancel()
s.unregisterTaskCancel(task.ID)
}()
executionCtx = certificate.WithProgressReporter(executionCtx, func(progressCtx context.Context, progressStage, progressMessage string) error {
return s.tasks.UpdateTask(progressCtx, task.ID, "running", progressStage, progressMessage, &now, nil)
})
certificateResult, deploymentReport, issueErr := s.issueCertificate(executionCtx, task.DomainID)
deploymentReport = sanitizeDeploymentReport(deploymentReport)
finished := time.Now().UTC()