Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Shubhendu Ram Tripathi <[email protected]>
  • Loading branch information
shtripat committed Jul 2, 2024
1 parent a7777d8 commit 601bcd1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
70 changes: 52 additions & 18 deletions cmd/batch-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -79,33 +80,66 @@ func mainBatchStatus(ctx *cli.Context) error {
ctxt, cancel := context.WithCancel(globalContext)
defer cancel()

ui := tea.NewProgram(initBatchJobMetricsUI(jobID))

_, e := client.DescribeBatchJob(ctxt, jobID)
nosuchJob := madmin.ToErrorResponse(e).Code == "XMinioAdminNoSuchJob"
if nosuchJob {
e = nil
if !globalJSON {
console.Infoln("Unable to find an active job, attempting to list from previously run jobs")
}
}
fatalIf(probe.NewError(e), "Unable to lookup job status")

ui := tea.NewProgram(initBatchJobMetricsUI(jobID))
go func() {
res, e := client.BatchJobStatus(ctxt, jobID)
fatalIf(probe.NewError(e), "Unable to lookup job status")
if globalJSON {
printMsg(batchJobStatusMessage{
Status: "success",
Metric: res.LastMetric,
go func() {
res, e := client.BatchJobStatus(ctxt, jobID)
fatalIf(probe.NewError(e), "Unable to lookup job status")
if globalJSON {
printMsg(batchJobStatusMessage{
Status: "success",
Metric: res.LastMetric,
})
if res.LastMetric.Complete || res.LastMetric.Failed {
cancel()
return
}
} else {
ui.Send(res.LastMetric)
}
}()
} else {
go func() {
opts := madmin.MetricsOptions{
Type: madmin.MetricsBatchJobs,
ByJobID: jobID,
Interval: time.Second,
}
e := client.Metrics(ctxt, opts, func(metrics madmin.RealtimeMetrics) {
if globalJSON {
if metrics.Aggregated.BatchJobs == nil {
cancel()
return
}

job, ok := metrics.Aggregated.BatchJobs.Jobs[jobID]
if !ok {
cancel()
return
}

printMsg(metricsMessage{RealtimeMetrics: metrics})
if job.Complete || job.Failed {
cancel()
return
}
} else {
ui.Send(metrics)
}
})
if res.LastMetric.Complete || res.LastMetric.Failed {
cancel()
return
if e != nil && !errors.Is(e, context.Canceled) {
fatalIf(probe.NewError(e).Trace(ctx.Args()...), "Unable to get current batch status")
}
} else {
ui.Send(res.LastMetric)
}
}()
}()
}
fatalIf(probe.NewError(e), "Unable to lookup job status")

if !globalJSON {
if _, e := ui.Run(); e != nil {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,3 @@ require (
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

replace github.com/minio/madmin-go/v3 v3.0.50 => github.com/vadmeste/madmin-go/v3 v3.0.0-20240506102820-f788488bde85
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ github.com/minio/colorjson v1.0.7 h1:n69M42mIuQHdzbsxlmwji1zxDypaw4o39rHjAmX4Dh4
github.com/minio/colorjson v1.0.7/go.mod h1:9LGM5yybI+GuhSbuzAerbSgvFb4j8ux9NzyONR+NrAY=
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
github.com/minio/madmin-go/v3 v3.0.55-0.20240603092915-420a67132c32 h1:9se7/S4AlN2k/B1E7A8m1m07DM3p0JnIOzVhDuAV2PI=
github.com/minio/madmin-go/v3 v3.0.55-0.20240603092915-420a67132c32/go.mod h1:IFAwr0XMrdsLovxAdCcuq/eoL4nRuMVQQv0iubJANQw=
github.com/minio/madmin-go/v3 v3.0.58-0.20240701162942-671010069ecb h1:6Hx1+R0GR79Vt4gOKgadH4OG8tkrq/UNyxfmR1C7C14=
github.com/minio/madmin-go/v3 v3.0.58-0.20240701162942-671010069ecb/go.mod h1:IFAwr0XMrdsLovxAdCcuq/eoL4nRuMVQQv0iubJANQw=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
Expand Down

0 comments on commit 601bcd1

Please sign in to comment.