@@ -10,11 +10,9 @@ import (
1010 "github.com/zgsm-ai/codebase-indexer/internal/tracer"
1111
1212 "github.com/panjf2000/ants/v2"
13- "github.com/zgsm-ai/codebase-indexer/internal/dao/model"
1413 "github.com/zgsm-ai/codebase-indexer/internal/errs"
1514 "github.com/zgsm-ai/codebase-indexer/internal/svc"
16- "github.com/zgsm-ai/codebase-indexer/internal/types"
17- "github.com/zgsm-ai/codebase-indexer/pkg/utils"
15+ // "github.com/zgsm-ai/codebase-indexer/internal/types"
1816)
1917
2018// baseProcessor 包含所有处理器共有的字段和方法
@@ -30,76 +28,77 @@ type baseProcessor struct {
3028
3129// initTaskHistory 初始化任务历史记录
3230func (p * baseProcessor ) initTaskHistory (ctx context.Context , taskType string ) error {
33- taskHistory := & model.IndexHistory {
34- SyncID : p .params .SyncID ,
35- CodebaseID : p .params .CodebaseID ,
36- CodebasePath : p .params .CodebasePath ,
37- TaskType : taskType ,
38- Status : types .TaskStatusPending ,
39- StartTime : utils .CurrentTime (),
40- }
41- if err := p .svcCtx .Querier .IndexHistory .WithContext (ctx ).Save (taskHistory ); err != nil {
42- tracer .WithTrace (ctx ).Errorf ("insert task history failed: %v, data:%v" , err , taskHistory )
43- return errs .InsertDatabaseFailed
44- }
45- p .taskHistoryId = taskHistory .ID
31+ // taskHistory := &model.IndexHistory{
32+ // SyncID: p.params.SyncID,
33+ // CodebaseID: p.params.CodebaseID,
34+ // CodebasePath: p.params.CodebasePath,
35+ // TaskType: taskType,
36+ // Status: types.TaskStatusPending,
37+ // StartTime: utils.CurrentTime(),
38+ // }
39+ // if err := p.svcCtx.Querier.IndexHistory.WithContext(ctx).Save(taskHistory); err != nil {
40+ // tracer.WithTrace(ctx).Errorf("insert task history failed: %v, data:%v", err, taskHistory)
41+ // return errs.InsertDatabaseFailed
42+ // }
43+ // p.taskHistoryId = taskHistory.ID
4644 return nil
4745}
4846
4947// updateTaskSuccess 更新任务状态为成功
5048func (p * baseProcessor ) updateTaskSuccess (ctx context.Context ) error {
51- progress := float64 (1 )
52- m := & model.IndexHistory {
53- ID : p .taskHistoryId ,
54- Status : types .TaskStatusSuccess ,
55- Progress : & progress ,
56- EndTime : utils .CurrentTime (),
57- TotalFileCount : & p .totalFileCnt ,
58- TotalSuccessCount : & p .successFileCnt ,
59- TotalFailCount : & p .failedFileCnt ,
60- TotalIgnoreCount : & p .ignoreFileCnt ,
61- }
62-
63- res , err := p .svcCtx .Querier .IndexHistory .WithContext (ctx ).
64- Where (p .svcCtx .Querier .IndexHistory .ID .Eq (m .ID )).
65- Updates (m )
66- if err != nil {
67- tracer .WithTrace (ctx ).Errorf ("update task history %d failed: %v, model:%v" , p .params .CodebaseID , err , m )
68- return fmt .Errorf ("upate task success failed: %w" , err )
69- }
70- if res .RowsAffected == 0 {
71- tracer .WithTrace (ctx ).Errorf ("update task history %d failed: %v, model:%v" , p .params .CodebaseID , err , m )
72- return fmt .Errorf ("upate task success failed, codebaseId %d not found in database" , p .params .CodebaseID )
73- }
74- if res .Error != nil {
75- tracer .WithTrace (ctx ).Errorf ("update task history %d failed: %v, model:%v" , p .params .CodebaseID , err , m )
76- return fmt .Errorf ("upate task success failed: %w" , res .Error )
77- }
49+ // progress := float64(1)
50+ // m := &model.IndexHistory{
51+ // ID: p.taskHistoryId,
52+ // Status: types.TaskStatusSuccess,
53+ // Progress: &progress,
54+ // EndTime: utils.CurrentTime(),
55+ // TotalFileCount: &p.totalFileCnt,
56+ // TotalSuccessCount: &p.successFileCnt,
57+ // TotalFailCount: &p.failedFileCnt,
58+ // TotalIgnoreCount: &p.ignoreFileCnt,
59+ // }
60+
61+ // res, err := p.svcCtx.Querier.IndexHistory.WithContext(ctx).
62+ // Where(p.svcCtx.Querier.IndexHistory.ID.Eq(m.ID)).
63+ // Updates(m)
64+ // if err != nil {
65+ // tracer.WithTrace(ctx).Errorf("update task history %d failed: %v, model:%v", p.params.CodebaseID, err, m)
66+ // return fmt.Errorf("upate task success failed: %w", err)
67+ // }
68+ // if res.RowsAffected == 0 {
69+ // tracer.WithTrace(ctx).Errorf("update task history %d failed: %v, model:%v", p.params.CodebaseID, err, m)
70+ // return fmt.Errorf("upate task success failed, codebaseId %d not found in database", p.params.CodebaseID)
71+ // }
72+ // if res.Error != nil {
73+ // tracer.WithTrace(ctx).Errorf("update task history %d failed: %v, model:%v", p.params.CodebaseID, err, m)
74+ // return fmt.Errorf("upate task success failed: %w", res.Error)
75+ // }
7876 return nil
7977}
8078
8179// handleIfTaskFailed 处理任务失败情况
8280func (p * baseProcessor ) handleIfTaskFailed (ctx context.Context , err error ) bool {
83- if err != nil {
84- tracer .WithTrace (ctx ).Errorf ("index task failed, err: %v" , err )
85- if errors .Is (err , errs .InsertDatabaseFailed ) {
86- return true
87- }
88- status := types .TaskStatusFailed
89- if errors .Is (err , errs .RunTimeout ) {
90- status = types .TaskStatusTimeout
91- }
92- _ , err = p .svcCtx .Querier .IndexHistory .WithContext (ctx ).
93- Where (p .svcCtx .Querier .IndexHistory .ID .Eq (p .taskHistoryId )).
94- UpdateColumnSimple (p .svcCtx .Querier .IndexHistory .Status .Value (status ),
95- p .svcCtx .Querier .IndexHistory .ErrorMessage .Value (err .Error ()))
96- if err != nil {
97- tracer .WithTrace (ctx ).Errorf ("update task history %d failed: %v" , p .params .CodebaseID , err )
98- }
99-
100- return true
101- }
102- return false
81+ return true
82+ // if err != nil {
83+ // tracer.WithTrace(ctx).Errorf("index task failed, err: %v", err)
84+ // if errors.Is(err, errs.InsertDatabaseFailed) {
85+ // return true
86+ // }
87+ // status := types.TaskStatusFailed
88+ // if errors.Is(err, errs.RunTimeout) {
89+ // status = types.TaskStatusTimeout
90+ // }
91+ // _, err = p.svcCtx.Querier.IndexHistory.WithContext(ctx).
92+ // Where(p.svcCtx.Querier.IndexHistory.ID.Eq(p.taskHistoryId)).
93+ // UpdateColumnSimple(p.svcCtx.Querier.IndexHistory.Status.Value(status),
94+ // p.svcCtx.Querier.IndexHistory.ErrorMessage.Value(err.Error()))
95+ // if err != nil {
96+ // tracer.WithTrace(ctx).Errorf("update task history %d failed: %v", p.params.CodebaseID, err)
97+ // }
98+
99+ // return true
100+ // }
101+ // return false
103102}
104103
105104// processFilesConcurrently 并发处理文件
0 commit comments