fix(task): prevent duplicate Slurm job submission on backend restart
RecoverStuckTasks now skips tasks that already have a slurm_job_id, and ProcessTask adds a guard before the submitting step to prevent re-submission even if a task is incorrectly re-enqueued. Also deprecates POST /api/v1/jobs/submit endpoint (replaced by POST /tasks) and comments out related handlers and tests.
This commit is contained in:
@@ -22,29 +22,31 @@ func NewJobHandler(jobSvc *service.JobService, logger *zap.Logger) *JobHandler {
|
||||
return &JobHandler{jobSvc: jobSvc, logger: logger}
|
||||
}
|
||||
|
||||
// [已弃用] SubmitJob 已被 POST /tasks 取代。
|
||||
// 保留方法体以防需要回滚。
|
||||
// SubmitJob handles POST /api/v1/jobs/submit.
|
||||
func (h *JobHandler) SubmitJob(c *gin.Context) {
|
||||
var req model.SubmitJobRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
h.logger.Warn("bad request", zap.String("method", "SubmitJob"), zap.String("error", "invalid request body"))
|
||||
server.BadRequest(c, "invalid request body")
|
||||
return
|
||||
}
|
||||
if req.Script == "" {
|
||||
h.logger.Warn("bad request", zap.String("method", "SubmitJob"), zap.String("error", "script is required"))
|
||||
server.BadRequest(c, "script is required")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := h.jobSvc.SubmitJob(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
h.logger.Error("handler error", zap.String("method", "SubmitJob"), zap.Int("status", http.StatusBadGateway), zap.Error(err))
|
||||
server.ErrorWithStatus(c, http.StatusBadGateway, "slurm error: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
server.Created(c, resp)
|
||||
}
|
||||
// func (h *JobHandler) SubmitJob(c *gin.Context) {
|
||||
// var req model.SubmitJobRequest
|
||||
// if err := c.ShouldBindJSON(&req); err != nil {
|
||||
// h.logger.Warn("bad request", zap.String("method", "SubmitJob"), zap.String("error", "invalid request body"))
|
||||
// server.BadRequest(c, "invalid request body")
|
||||
// return
|
||||
// }
|
||||
// if req.Script == "" {
|
||||
// h.logger.Warn("bad request", zap.String("method", "SubmitJob"), zap.String("error", "script is required"))
|
||||
// server.BadRequest(c, "script is required")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// resp, err := h.jobSvc.SubmitJob(c.Request.Context(), &req)
|
||||
// if err != nil {
|
||||
// h.logger.Error("handler error", zap.String("method", "SubmitJob"), zap.Int("status", http.StatusBadGateway), zap.Error(err))
|
||||
// server.ErrorWithStatus(c, http.StatusBadGateway, "slurm error: "+err.Error())
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// server.Created(c, resp)
|
||||
// }
|
||||
|
||||
// GetJobs handles GET /api/v1/jobs with pagination.
|
||||
func (h *JobHandler) GetJobs(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user