完善任务部分成功状态与运行概览
补充证书部署部分成功的任务状态、HTTP响应和前端任务展示,并增加对应测试。
This commit is contained in:
1 parent
a9f17c740a
commit
2b9d82df2f
7 files changed
+70
-13
No files matched your search
@@ -148,10 +148,14 @@ func (s *Server) executeCertificateIssueTask(c *gin.Context, task repository.Tas
|
||||
status := "success"
|
||||
message := "证书申请和部署完成"
|
||||
cancelled := false
|
||||
partial := issueErr == nil && deploymentReport.Status == "partial"
|
||||
partial := deploymentReport.Status == "partial"
|
||||
if issueErr != nil {
|
||||
status = "failed"
|
||||
message = certificateTaskErrorMessage(issueErr)
|
||||
if partial {
|
||||
status = "partial_success"
|
||||
message = "\u8bc1\u4e66\u5df2\u7b7e\u53d1\uff0c\u4f46\u4ec5\u90e8\u5206\u670d\u52a1\u5668\u90e8\u7f72\u6210\u529f"
|
||||
}
|
||||
if s.logger != nil {
|
||||
s.logger.Error("证书任务执行失败", "task_id", task.ID, "domain_id", task.DomainID, "error", issueErr)
|
||||
}
|
||||
@@ -181,7 +185,7 @@ func (s *Server) executeCertificateIssueTask(c *gin.Context, task repository.Tas
|
||||
task.UpdatedAt = finished
|
||||
if s.audit != nil {
|
||||
auditStatus := status
|
||||
if issueErr != nil && status != "cancelled" {
|
||||
if issueErr != nil && status != "cancelled" && status != "partial_success" {
|
||||
auditStatus = "error"
|
||||
}
|
||||
_ = s.audit.CreateAuditLog(context.Background(), repository.AuditLog{
|
||||
@@ -198,6 +202,8 @@ func (s *Server) executeCertificateIssueTask(c *gin.Context, task repository.Tas
|
||||
responseStatus := http.StatusBadGateway
|
||||
if status == "cancelled" {
|
||||
responseStatus = http.StatusConflict
|
||||
} else if status == "partial_success" {
|
||||
responseStatus = http.StatusMultiStatus
|
||||
} else if errors.Is(issueErr, context.DeadlineExceeded) {
|
||||
responseStatus = http.StatusGatewayTimeout
|
||||
}
|
||||
|
||||
@@ -563,3 +563,30 @@ func TestTaskAPIRecordsPartialDeploymentSuccess(t *testing.T) {
|
||||
t.Fatalf("partial audit status: %+v %v", logs, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskAPIRecordsPartialDeploymentFailureAsPartialSuccess(t *testing.T) {
|
||||
server, taskRepo, auditRepo, closeDB := newTaskAPITestServer(t, func(_ context.Context, id string) (certificate.IssueResult, deployment.Report, error) {
|
||||
return certificate.IssueResult{DomainID: id}, deployment.Report{
|
||||
Total: 2, Success: 1, Failed: 1, Status: "partial",
|
||||
}, errors.New("deployment partially failed")
|
||||
})
|
||||
defer closeDB()
|
||||
|
||||
response := httptest.NewRecorder()
|
||||
serveAdminHTTP(server, response, httptest.NewRequest(http.MethodPost, "/api/v1/domains/domain-1/issue", nil))
|
||||
if response.Code != http.StatusMultiStatus {
|
||||
t.Fatalf("partial failure response: %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
items, err := taskRepo.ListTasks(context.Background(), "domain-1", 10)
|
||||
if err != nil || len(items) != 1 || items[0].Status != "partial_success" {
|
||||
t.Fatalf("partial failure task status: %+v %v", items, err)
|
||||
}
|
||||
attempts, err := taskRepo.ListAttempts(context.Background(), items[0].ID)
|
||||
if err != nil || len(attempts) != 1 || attempts[0].Status != "partial_success" {
|
||||
t.Fatalf("partial failure attempt status: %+v %v", attempts, err)
|
||||
}
|
||||
logs, err := auditRepo.ListAuditLogs(context.Background(), 10)
|
||||
if err != nil || len(logs) != 1 || logs[0].Status != "partial_success" {
|
||||
t.Fatalf("partial failure audit status: %+v %v", logs, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user