refactor(service): disable SubmitFromApplication fallback, fully replaced by POST /tasks

- Comment out SubmitFromApplication method and its fallback path

- Comment out 5 tests that tested the old direct-submission code

- Remove unused imports after commenting out the method

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-16 15:15:42 +08:00
parent 80f2bd32d9
commit 36d842350c
2 changed files with 66 additions and 58 deletions

View File

@@ -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,12 +52,14 @@ 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 {
// [已禁用] 旧的直接提交路径,已被 TaskService 管道取代。生产环境中 taskSvc 始终非 nil此分支不会执行。
// if s.taskSvc != nil {
req := &model.CreateTaskRequest{
AppID: applicationID,
Values: values,
@@ -70,45 +67,45 @@ func (s *ApplicationService) SubmitFromApplication(ctx context.Context, applicat
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, &params); 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, &params); 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)
} */

View File

@@ -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)
}
}
*/