Skip to content

Commit

Permalink
process: don't let multiple statuses run simultaneously for now (#240)
Browse files Browse the repository at this point in the history
* add process id to log

Signed-off-by: Nandor Kracser <[email protected]>

* process: don't let multiple statuses run simultaneously for now

Signed-off-by: Nandor Kracser <[email protected]>
  • Loading branch information
bonifaido authored Apr 30, 2020
1 parent e3175a7 commit af4c4b9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func TailProcess(banzaiCli cli.Cli, processId string) error {
client := banzaiCli.Client()
orgID := banzaiCli.Context().OrganizationID()

status := spinner.NewStatus()
status.Start(fmt.Sprintf("[%s] tailing process %s", time.Now().Local().Format(time.RFC3339), processId))

statuses := map[string]*spinner.Status{}

processVisibleChecks := 0
Expand All @@ -49,25 +52,34 @@ func TailProcess(banzaiCli cli.Cli, processId string) error {
return errors.WrapIf(err, "failed to list node pool update processes")
}
defer resp.Body.Close()
status.End(true)

if resp.StatusCode < 200 || resp.StatusCode > 299 {
return errors.NewWithDetails("node pool update process list failed with http status code", "status_code", resp.StatusCode)
}

for i := processedEvents; i < len(process.Events); i++ {
event := process.Events[i]
processedEvents++
if s, ok := statuses[event.Type]; !ok {
// TODO(nandi) don't let multiple statuses run for now
if len(statuses) > 0 {
continue
}

status := spinner.NewStatus()
status.Start(fmt.Sprintf("[%s] executing %s activity %s", event.Timestamp.Local().Format(time.RFC3339), event.Type, event.Log))
statuses[event.Type] = status

if i == len(process.Events)-1 {
time.Sleep(2 * time.Second)
}

processedEvents++
} else if event.Status != pipeline.RUNNING {
s.End(event.Status == pipeline.FINISHED)
delete(statuses, event.Type)

processedEvents++
} else {
if i == len(process.Events)-1 {
time.Sleep(2 * time.Second)
Expand All @@ -76,8 +88,8 @@ func TailProcess(banzaiCli cli.Cli, processId string) error {
}

if process.Status == pipeline.FINISHED {
_, err = fmt.Fprintf(banzaiCli.Out(), process.Type+" process finished")
return err
_, _ = fmt.Fprintf(banzaiCli.Out(), "%s process finished", process.Type)
return nil
} else if process.Status != pipeline.RUNNING {
return errors.New(fmt.Sprintf("%s process %s: %s", process.Type, process.Status, process.Log))
}
Expand Down

0 comments on commit af4c4b9

Please sign in to comment.