Implement review suggestions

This commit is contained in:
Maximilian Paß
2021-12-17 17:09:01 +01:00
parent 0571b10b5c
commit d57a0c07b8
10 changed files with 104 additions and 106 deletions

View File

@@ -99,7 +99,11 @@ func FindOrCreateConfigTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task {
if task.Config == nil {
task.Config = make(map[string]interface{})
}
task.Config["command"] = ConfigTaskCommand
// This function should allow concurrency in the "Find" case.
// Therefore, this condition is necessary to remove concurrent writes in the "Find" case.
if v, ok := task.Config["command"]; !(ok && v == ConfigTaskCommand) {
task.Config["command"] = ConfigTaskCommand
}
return task
}
@@ -125,8 +129,14 @@ func FindOrCreateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task {
if task.Config == nil {
task.Config = make(map[string]interface{})
}
task.Config["command"] = TaskCommand
task.Config["args"] = TaskArgs
// This function should allow concurrency in the "Find" case.
if v, ok := task.Config["command"]; !(ok && v == TaskCommand) {
task.Config["command"] = TaskCommand
}
v, ok := task.Config["args"]
if args, isStringArray := v.([]string); !(ok && isStringArray && len(args) == 1 && args[0] == TaskArgs[0]) {
task.Config["args"] = TaskArgs
}
return task
}