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 write taskId.data #190

Merged
merged 1 commit into from
Apr 21, 2022
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
40 changes: 39 additions & 1 deletion server/pkg/webserver/controller/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func ImportData(ctx iris.Context) base.Result {
}
}

runnerLogger := logger.NewRunnerLogger("")
runnerLogger := logger.NewRunnerLogger(*params.ConfigBody.LogPath)
if params.ConfigPath != "" {
params.ConfigBody, err = importconfig.Parse(params.ConfigPath, runnerLogger)
if err != nil {
Expand Down Expand Up @@ -129,6 +129,44 @@ func ImportData(ctx iris.Context) base.Result {
Message: err.Error(),
}
}
// write taskId to file
muTaskId.Lock()
taskIdBytes, err := ioutil.ReadFile(config.Cfg.Web.TaskIdPath)
if err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return base.Response{
Code: base.Error,
Message: err.Error(),
}
}
taskIdJSON := make(map[string]bool)
if len(taskIdBytes) != 0 {
if err := json.Unmarshal(taskIdBytes, &taskIdJSON); err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return base.Response{
Code: base.Error,
Message: err.Error(),
}
}
}
taskIdJSON[taskID] = true
bytes, err := json.Marshal(taskIdJSON)
if err != nil {
zap.L().Warn("read taskId file error", zap.Error(err))
return base.Response{
Code: base.Error,
Message: err.Error(),
}
}
err = ioutil.WriteFile(config.Cfg.Web.TaskIdPath, bytes, 777)
if err != nil {
zap.L().Warn("write taskId file error", zap.Error(err))
return base.Response{
Code: base.Error,
Message: err.Error(),
}
}
defer muTaskId.Unlock()
return base.Response{
Code: base.Success,
Data: []string{taskID},
Expand Down
2 changes: 1 addition & 1 deletion server/pkg/webserver/service/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func CreateConfigFile(dir string, config importconfig.YAMLConfig) error {
func Import(taskID string, conf *importconfig.YAMLConfig) (err error) {
zap.L().Debug(fmt.Sprintf("Start a import task: `%s`", taskID))

runnerLogger := logger.NewRunnerLogger("")
runnerLogger := logger.NewRunnerLogger(*conf.LogPath)
if err := conf.ValidateAndReset("", runnerLogger); err != nil {
return err
}
Expand Down