reimplemented logging of wf when executed locally
This commit is contained in:
28
main.go
28
main.go
@@ -143,8 +143,8 @@ func executeOutside(argo_file_path string, stepMax int) {
|
||||
var stdout, stderr io.ReadCloser
|
||||
// var stderr io.ReadCloser
|
||||
var err error
|
||||
logger.Debug().Msg("executing :" + "argo submit --log " + argo_file_path + " --serviceaccount sa-" + conf.GetConfig().ExecutionID + " -n " + conf.GetConfig().ExecutionID)
|
||||
cmd := exec.Command("argo", "submit", "--log", argo_file_path, "--serviceaccount", "sa-"+conf.GetConfig().ExecutionID, "-n", conf.GetConfig().ExecutionID )
|
||||
logger.Debug().Msg("executing :" + "argo submit --watch " + argo_file_path + " --serviceaccount sa-" + conf.GetConfig().ExecutionID + " -n " + conf.GetConfig().ExecutionID)
|
||||
cmd := exec.Command("argo", "submit", "--watch", argo_file_path, "--serviceaccount", "sa-"+conf.GetConfig().ExecutionID, "-n", conf.GetConfig().ExecutionID )
|
||||
if stdout, err = cmd.StdoutPipe(); err != nil {
|
||||
wf_logger.Error().Msg("Could not retrieve stdoutpipe " + err.Error())
|
||||
return
|
||||
@@ -154,10 +154,11 @@ func executeOutside(argo_file_path string, stepMax int) {
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
split := strings.Split(argo_file_path, "_")
|
||||
argoLogs := models.NewArgoLogs(split[0], "argo", stepMax)
|
||||
argoLogs := models.NewArgoLogs(split[0], conf.GetConfig().ExecutionID, stepMax)
|
||||
argoLogs.StartStepRecording(argoLogs.NewWatch(), wf_logger)
|
||||
argoLogs.IsStreaming = true
|
||||
go logWorkflow(argo_file_path, stepMax, stdout, argoLogs.NewWatch(), argoLogs.NewWatch(), argoLogs, []string{}, &wg)
|
||||
argoLogs.IsStreaming = true // Used to determine wether or not the logs are read from a docker container or on localhost
|
||||
// go logWorkflow(argo_file_path, stepMax, stdout, argoLogs.NewWatch(), argoLogs.NewWatch(), argoLogs, []string{}, &wg)
|
||||
go models.LogLocalWorkflow(stdout,&wg)
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
wf_logger.Error().Msg("Could not execute argo submit")
|
||||
@@ -167,6 +168,10 @@ func executeOutside(argo_file_path string, stepMax int) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// !!!! BUGGED !!!!
|
||||
// Should be refactored to create a function dedicated to logging output from execution in a container
|
||||
// LogLocalWorkflow() has been implemented to be used when oc-monitord is executed locally
|
||||
|
||||
// We could improve this function by creating an object with the same attribute as the output
|
||||
// and only send a new log if the current object has different values than the previous
|
||||
func logWorkflow(argo_file_path string, stepMax int, pipe io.ReadCloser,
|
||||
@@ -183,12 +188,8 @@ func logWorkflow(argo_file_path string, stepMax int, pipe io.ReadCloser,
|
||||
wg.Add(1)
|
||||
}
|
||||
seeit++
|
||||
} else if count == 0 {
|
||||
if argoLogs.IsStreaming {
|
||||
continue
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} else if count == 0 && !argoLogs.IsStreaming {
|
||||
break
|
||||
}
|
||||
if count == 1 {
|
||||
see = log
|
||||
@@ -202,7 +203,7 @@ func logWorkflow(argo_file_path string, stepMax int, pipe io.ReadCloser,
|
||||
current_watch.Logs = append(current_watch.Logs, strings.ReplaceAll(log, "\"", ""))
|
||||
}
|
||||
count++
|
||||
if strings.Contains(log, "sub-process exited") {
|
||||
if strings.Contains(log, "sub-process exited") || argoLogs.IsStreaming {
|
||||
current_watch = argoLogs.StopStepRecording(current_watch)
|
||||
argoLogs.Seen = append(argoLogs.Seen, see)
|
||||
if checkStatus(current_watch, previous_watch, argoLogs) {
|
||||
@@ -223,6 +224,9 @@ func logWorkflow(argo_file_path string, stepMax int, pipe io.ReadCloser,
|
||||
}
|
||||
previous_watch = current_watch
|
||||
current_watch = &models.ArgoWatch{}
|
||||
if argoLogs.IsStreaming {
|
||||
current_watch.Logs = []string{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user