补齐任务部署结果持久化与查询接口
保存批量部署每台服务器的执行结果,新增数据库迁移、仓储查询和任务部署结果接口,并补充应用与仓储测试。
This commit is contained in:
1 parent
253f2bd824
commit
126cb6d566
11 files changed
+330
-1
No files matched your search
@@ -222,6 +222,7 @@ func (s *Server) registerRoutes() {
|
||||
api.DELETE("/tasks/:id", s.cancelTask)
|
||||
api.POST("/tasks/:id/retry", s.retryTask)
|
||||
api.GET("/tasks/:id/attempts", s.listTaskAttempts)
|
||||
api.GET("/tasks/:id/deployment-results", s.listTaskDeploymentResults)
|
||||
|
||||
adminAPI.GET("/settings", s.getSettings)
|
||||
adminAPI.PUT("/settings", s.requireSuperAdminSystemConfig, s.updateSettings)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/certificate"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/deployment"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/domain"
|
||||
"git.pcux.cn/xuans/Scert/backend/internal/repository"
|
||||
)
|
||||
@@ -177,6 +178,9 @@ func (s *Server) executeCertificateIssueTask(c *gin.Context, task repository.Tas
|
||||
})
|
||||
certificateResult, deploymentReport, issueErr := s.issueCertificate(executionCtx, task.DomainID)
|
||||
deploymentReport = sanitizeDeploymentReport(deploymentReport)
|
||||
if recordErr := s.tasks.RecordTaskDeploymentResults(context.Background(), task.ID, attempt.ID, attempt.AttemptNumber, taskDeploymentResults(deploymentReport)); recordErr != nil {
|
||||
issueErr = errors.Join(issueErr, recordErr)
|
||||
}
|
||||
finished := time.Now().UTC()
|
||||
status := "success"
|
||||
message := "证书申请和部署完成"
|
||||
@@ -503,6 +507,52 @@ func (s *Server) listTaskAttempts(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": items})
|
||||
}
|
||||
|
||||
func (s *Server) listTaskDeploymentResults(c *gin.Context) {
|
||||
reader, ok := s.projectTaskReader(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
actorID := c.GetString(authenticatedActorKey)
|
||||
if _, err := reader.GetVisibleTask(c.Request.Context(), actorID, c.Param("id")); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) || errors.Is(err, repository.ErrProjectAccessDenied) {
|
||||
s.writeError(c, http.StatusForbidden, "无权访问此任务", nil)
|
||||
return
|
||||
}
|
||||
s.writeError(c, http.StatusInternalServerError, "读取任务失败", err)
|
||||
return
|
||||
}
|
||||
items, err := reader.ListVisibleTaskDeploymentResults(c.Request.Context(), actorID, c.Param("id"))
|
||||
if err != nil {
|
||||
s.writeError(c, http.StatusInternalServerError, "查询任务部署结果失败", err)
|
||||
return
|
||||
}
|
||||
for index := range items {
|
||||
if items[index].Status == "failed" {
|
||||
items[index].Message = "证书部署失败"
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"items": items})
|
||||
}
|
||||
|
||||
func taskDeploymentResults(report deployment.Report) []repository.TaskDeploymentResult {
|
||||
if len(report.Results) == 0 {
|
||||
return nil
|
||||
}
|
||||
items := make([]repository.TaskDeploymentResult, 0, len(report.Results))
|
||||
for index, item := range report.Results {
|
||||
items = append(items, repository.TaskDeploymentResult{
|
||||
ResultIndex: index,
|
||||
ServerID: item.ServerID,
|
||||
Server: item.Server,
|
||||
Status: item.Status,
|
||||
Message: item.Message,
|
||||
BackupID: item.BackupID,
|
||||
})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (s *Server) listAuditLogs(c *gin.Context) {
|
||||
if !s.requireProjectResourceReader(c) {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user