Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add err message after import fail #64

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions service/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ func Import(taskID string, configPath string, configBody *config.YAMLConfig) (er
task.TaskStatus = StatusAborted.String()

err, _ := rerr.(importerErrors.ImporterError)

result.ErrorResult.ErrorCode = err.ErrCode
result.ErrorResult.ErrorMsg = err.ErrMsg.Error()

task.TaskMessage = err.ErrMsg.Error()
logs.Error(fmt.Sprintf("Failed to finish a import task: `%s`, task result: `%v`", taskID, result))
} else {
task.TaskStatus = StatusFinished.String()
Expand Down Expand Up @@ -113,10 +112,10 @@ func ImportAction(taskID string, taskAction TaskAction) (result ActionResult, er
func actionQuery(taskID string, result *ActionResult) {
// a temp task obj for response
task := Task{}

if t, ok := GetTaskMgr().GetTask(taskID); ok {
task.TaskID = t.TaskID
task.TaskStatus = t.TaskStatus
task.TaskMessage = t.TaskMessage
result.Results = append(result.Results, task)
result.Msg = "Task query successfully"
} else {
Expand Down
7 changes: 4 additions & 3 deletions service/importer/taskmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ type TaskMgr struct {
type Task struct {
runner *cmd.Runner

TaskID string `json:"taskID"`
TaskStatus string `json:"taskStatus"`
TaskID string `json:"taskID"`
TaskStatus string `json:"taskStatus"`
TaskMessage string `json:"taskMessage"`
}

func init() {
Expand Down Expand Up @@ -162,7 +163,7 @@ func initDB() {
GetTaskMgr().db = _db

sqlStmt := `
create table tasks (taskID integer not null primary key, taskStatus text);
create table tasks (taskID integer not null primary key, taskStatus text, taskMessage text);
delete from tasks;
`
_, err = GetTaskMgr().db.Exec(sqlStmt)
Expand Down