diff --git a/internal/service/application_service.go b/internal/service/application_service.go index ffa3615..73e2b0a 100644 --- a/internal/service/application_service.go +++ b/internal/service/application_service.go @@ -2,11 +2,6 @@ package service import ( "context" - "encoding/json" - "fmt" - "os" - "path/filepath" - "time" "gcy_hpc_server/internal/model" "gcy_hpc_server/internal/store" @@ -57,58 +52,60 @@ func (s *ApplicationService) DeleteApplication(ctx context.Context, id int64) er return s.store.Delete(ctx, id) } -// SubmitFromApplication orchestrates the full submission flow. +// [已禁用] 前端已全部迁移到 POST /tasks 接口,此方法不再被调用。 +/* // SubmitFromApplication orchestrates the full submission flow. // When TaskService is available, it delegates to ProcessTaskSync which creates // an hpc_tasks record and runs the full pipeline. Otherwise falls back to the // original direct implementation. func (s *ApplicationService) SubmitFromApplication(ctx context.Context, applicationID int64, values map[string]string) (*model.JobResponse, error) { - if s.taskSvc != nil { - req := &model.CreateTaskRequest{ - AppID: applicationID, - Values: values, - InputFileIDs: nil, // old API has no file_ids concept - TaskName: "", - } - return s.taskSvc.ProcessTaskSync(ctx, req) + // [已禁用] 旧的直接提交路径,已被 TaskService 管道取代。生产环境中 taskSvc 始终非 nil,此分支不会执行。 + // if s.taskSvc != nil { + req := &model.CreateTaskRequest{ + AppID: applicationID, + Values: values, + InputFileIDs: nil, // old API has no file_ids concept + TaskName: "", } + return s.taskSvc.ProcessTaskSync(ctx, req) + // } - // Fallback: original direct logic when TaskService not available - app, err := s.store.GetByID(ctx, applicationID) - if err != nil { - return nil, fmt.Errorf("get application: %w", err) - } - if app == nil { - return nil, fmt.Errorf("application %d not found", applicationID) - } - - var params []model.ParameterSchema - if len(app.Parameters) > 0 { - if err := json.Unmarshal(app.Parameters, ¶ms); err != nil { - return nil, fmt.Errorf("parse parameters: %w", err) - } - } - - if err := ValidateParams(params, values); err != nil { - return nil, err - } - - rendered := RenderScript(app.ScriptTemplate, params, values) - - workDir := "" - if s.workDirBase != "" { - safeName := SanitizeDirName(app.Name) - subDir := time.Now().Format("20060102_150405") + "_" + RandomSuffix(4) - workDir = filepath.Join(s.workDirBase, safeName, subDir) - if err := os.MkdirAll(workDir, 0777); err != nil { - return nil, fmt.Errorf("create work directory %s: %w", workDir, err) - } - // 绕过 umask,确保整条路径都有写权限 - for dir := workDir; dir != s.workDirBase; dir = filepath.Dir(dir) { - os.Chmod(dir, 0777) - } - os.Chmod(s.workDirBase, 0777) - } - - req := &model.SubmitJobRequest{Script: rendered, WorkDir: workDir} - return s.jobSvc.SubmitJob(ctx, req) -} + // // Fallback: original direct logic when TaskService not available + // app, err := s.store.GetByID(ctx, applicationID) + // if err != nil { + // return nil, fmt.Errorf("get application: %w", err) + // } + // if app == nil { + // return nil, fmt.Errorf("application %d not found", applicationID) + // } + // + // var params []model.ParameterSchema + // if len(app.Parameters) > 0 { + // if err := json.Unmarshal(app.Parameters, ¶ms); err != nil { + // return nil, fmt.Errorf("parse parameters: %w", err) + // } + // } + // + // if err := ValidateParams(params, values); err != nil { + // return nil, err + // } + // + // rendered := RenderScript(app.ScriptTemplate, params, values) + // + // workDir := "" + // if s.workDirBase != "" { + // safeName := SanitizeDirName(app.Name) + // subDir := time.Now().Format("20060102_150405") + "_" + RandomSuffix(4) + // workDir = filepath.Join(s.workDirBase, safeName, subDir) + // if err := os.MkdirAll(workDir, 0777); err != nil { + // return nil, fmt.Errorf("create work directory %s: %w", workDir, err) + // } + // // 绕过 umask,确保整条路径都有写权限 + // for dir := workDir; dir != s.workDirBase; dir = filepath.Dir(dir) { + // os.Chmod(dir, 0777) + // } + // os.Chmod(s.workDirBase, 0777) + // } + // + // req := &model.SubmitJobRequest{Script: rendered, WorkDir: workDir} + // return s.jobSvc.SubmitJob(ctx, req) +} */ diff --git a/internal/service/application_service_test.go b/internal/service/application_service_test.go index e46362a..9683a87 100644 --- a/internal/service/application_service_test.go +++ b/internal/service/application_service_test.go @@ -1,12 +1,8 @@ package service import ( - "context" - "encoding/json" "net/http" "net/http/httptest" - "os" - "path/filepath" "strings" "testing" @@ -198,6 +194,8 @@ func TestRenderScript_NewlineInValue(t *testing.T) { } } +// [已禁用] 测试的是旧的直接提交路径,该路径已被注释掉 +/* func TestSubmitFromApplication_Success(t *testing.T) { jobID := int32(42) appSvc, cleanup := setupApplicationService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -227,7 +225,10 @@ func TestSubmitFromApplication_Success(t *testing.T) { t.Errorf("JobID = %d, want 42", resp.JobID) } } +*/ +// [已禁用] 测试的是旧的直接提交路径,该路径已被注释掉 +/* func TestSubmitFromApplication_AppNotFound(t *testing.T) { appSvc, cleanup := setupApplicationService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) @@ -242,7 +243,10 @@ func TestSubmitFromApplication_AppNotFound(t *testing.T) { t.Errorf("error should mention 'not found', got: %v", err) } } +*/ +// [已禁用] 测试的是旧的直接提交路径,该路径已被注释掉 +/* func TestSubmitFromApplication_ValidationFail(t *testing.T) { appSvc, cleanup := setupApplicationService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) @@ -263,7 +267,10 @@ func TestSubmitFromApplication_ValidationFail(t *testing.T) { t.Errorf("error should mention 'missing', got: %v", err) } } +*/ +// [已禁用] 测试的是旧的直接提交路径,该路径已被注释掉 +/* func TestSubmitFromApplication_NoParameters(t *testing.T) { jobID := int32(99) appSvc, cleanup := setupApplicationService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -289,7 +296,10 @@ func TestSubmitFromApplication_NoParameters(t *testing.T) { t.Errorf("JobID = %d, want 99", resp.JobID) } } +*/ +// [已禁用] 前端已全部迁移到 POST /tasks 接口,此测试不再需要。 +/* func TestSubmitFromApplication_DelegatesToTaskService(t *testing.T) { jobID := int32(77) srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -354,3 +364,4 @@ func TestSubmitFromApplication_DelegatesToTaskService(t *testing.T) { t.Errorf("task Status = %q, want %q", task.Status, model.TaskStatusQueued) } } +*/