Skip to content

Commit 18542c9

Browse files
authored
fix: add err message after import fail (#64)
1 parent 8373e15 commit 18542c9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

service/importer/importer.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ func Import(taskID string, configPath string, configBody *config.YAMLConfig) (er
7070
task.TaskStatus = StatusAborted.String()
7171

7272
err, _ := rerr.(importerErrors.ImporterError)
73-
7473
result.ErrorResult.ErrorCode = err.ErrCode
7574
result.ErrorResult.ErrorMsg = err.ErrMsg.Error()
76-
75+
task.TaskMessage = err.ErrMsg.Error()
7776
logs.Error(fmt.Sprintf("Failed to finish a import task: `%s`, task result: `%v`", taskID, result))
7877
} else {
7978
task.TaskStatus = StatusFinished.String()
@@ -113,10 +112,10 @@ func ImportAction(taskID string, taskAction TaskAction) (result ActionResult, er
113112
func actionQuery(taskID string, result *ActionResult) {
114113
// a temp task obj for response
115114
task := Task{}
116-
117115
if t, ok := GetTaskMgr().GetTask(taskID); ok {
118116
task.TaskID = t.TaskID
119117
task.TaskStatus = t.TaskStatus
118+
task.TaskMessage = t.TaskMessage
120119
result.Results = append(result.Results, task)
121120
result.Msg = "Task query successfully"
122121
} else {

service/importer/taskmgr.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ type TaskMgr struct {
3333
type Task struct {
3434
runner *cmd.Runner
3535

36-
TaskID string `json:"taskID"`
37-
TaskStatus string `json:"taskStatus"`
36+
TaskID string `json:"taskID"`
37+
TaskStatus string `json:"taskStatus"`
38+
TaskMessage string `json:"taskMessage"`
3839
}
3940

4041
func init() {
@@ -162,7 +163,7 @@ func initDB() {
162163
GetTaskMgr().db = _db
163164

164165
sqlStmt := `
165-
create table tasks (taskID integer not null primary key, taskStatus text);
166+
create table tasks (taskID integer not null primary key, taskStatus text, taskMessage text);
166167
delete from tasks;
167168
`
168169
_, err = GetTaskMgr().db.Exec(sqlStmt)

0 commit comments

Comments
 (0)