补齐任务幂等并发保护

新增三数据库任务幂等登记迁移,在任务创建事务中防止重复幂等键,并补充并发回归测试与进度清单。
This commit is contained in:
xuans committed 2026-09-30 02:00:36 +08:00
1 parent 163b3e9c5d
commit 7e14bbf42f
11 files changed
+168 -5

No files matched your search

+11
View File
@@ -102,6 +102,17 @@ func (s *Server) issueDomainAsTask(c *gin.Context) {
Message: "等待执行证书申请", IdempotencyKey: idempotencyKey, CreatedAt: now, UpdatedAt: now,
}
if err := s.tasks.CreateTask(c.Request.Context(), task); err != nil {
if idempotencyKey != "" {
if existing, lookupErr := s.tasks.FindTaskByIdempotencyKey(c.Request.Context(), domainID, idempotencyKey); lookupErr == nil {
status := http.StatusOK
if existing.Status == "queued" || existing.Status == "running" {
status = http.StatusConflict
}
c.JSON(status, gin.H{"task": existing, "replayed": true})
s.issueTaskMu.Unlock()
return
}
}
s.issueTaskMu.Unlock()
s.writeError(c, http.StatusInternalServerError, "创建证书任务失败", err)
return