Skip to content

Commit

Permalink
fix(status): fix divide by zero (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardyok authored Oct 26, 2024
1 parent 1a0ff53 commit 6f30ce1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/gpud/command/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func cmdJoin(cliContext *cli.Context) (retErr error) {
return fmt.Errorf("failed to get machine uid: %w", err)
}

cmd := exec.Command("nproc")
cmd := exec.Command("nproc", "--all")
var out bytes.Buffer
cmd.Stdout = &out
if err = cmd.Run(); err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/gpud/command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func cmdStatus(cliContext *cli.Context) error {
fmt.Printf("%s failed to get package status: %v\n", warningSign, err)
return err
}
if len(packageStatus) == 0 {
fmt.Printf("no packages found\n")
return nil
}
if statusWatch {
fmt.Print("\033[2J\033[H")
}
Expand All @@ -58,7 +62,11 @@ func cmdStatus(cliContext *cli.Context) error {
progress += status.TotalTime.Milliseconds() * int64(status.Progress) / 100
}

fmt.Printf("Total progress: %v%%, Estimate time left: %v\n", progress*100/totalTime, time.Duration(totalTime-progress)*time.Millisecond)
var totalProgress int64
if totalTime != 0 {
totalProgress = progress * 100 / totalTime
}
fmt.Printf("Total progress: %v%%, Estimate time left: %v\n", totalProgress, time.Duration(totalTime-progress)*time.Millisecond)
if !statusWatch {
break
}
Expand Down

0 comments on commit 6f30ce1

Please sign in to comment.