fix: batch status responsiveness (#4661)
This commit is contained in:
+47
-17
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
@@ -61,25 +62,42 @@ func mainBatchStatus(ctx *cli.Context) error {
|
||||
defer cancel()
|
||||
|
||||
_, 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() {
|
||||
opts := madmin.MetricsOptions{
|
||||
Type: madmin.MetricsBatchJobs,
|
||||
ByJobID: jobID,
|
||||
Type: madmin.MetricsBatchJobs,
|
||||
ByJobID: jobID,
|
||||
Interval: time.Second,
|
||||
}
|
||||
e := client.Metrics(ctxt, opts, func(metrics madmin.RealtimeMetrics) {
|
||||
if globalJSON {
|
||||
printMsg(metricsMessage{RealtimeMetrics: metrics})
|
||||
return
|
||||
}
|
||||
if metrics.Aggregated.BatchJobs != nil {
|
||||
job := metrics.Aggregated.BatchJobs.Jobs[jobID]
|
||||
ui.Send(job)
|
||||
if job.Complete {
|
||||
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 e != nil && !errors.Is(e, context.Canceled) {
|
||||
@@ -92,6 +110,8 @@ func mainBatchStatus(ctx *cli.Context) error {
|
||||
cancel()
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to get current batch status")
|
||||
}
|
||||
} else {
|
||||
<-ctxt.Done()
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -128,9 +148,21 @@ func (m *batchJobMetricsUI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
case madmin.JobMetric:
|
||||
m.current = msg
|
||||
if msg.Complete {
|
||||
case madmin.RealtimeMetrics:
|
||||
metrics := msg
|
||||
if metrics.Aggregated.BatchJobs == nil {
|
||||
m.quitting = true
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
job, ok := metrics.Aggregated.BatchJobs.Jobs[m.jobID]
|
||||
if !ok {
|
||||
m.quitting = true
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
m.current = job
|
||||
if job.Complete || job.Failed {
|
||||
m.quitting = true
|
||||
return m, tea.Quit
|
||||
}
|
||||
@@ -173,11 +205,9 @@ func (m *batchJobMetricsUI) View() string {
|
||||
s.WriteString(m.spinner.View())
|
||||
} else {
|
||||
if m.current.Complete {
|
||||
if m.current.Replicate.ObjectsFailed == 0 {
|
||||
s.WriteString(m.spinner.Style.Render((tickCell + tickCell + tickCell)))
|
||||
} else {
|
||||
s.WriteString(m.spinner.Style.Render((crossTickCell + crossTickCell + crossTickCell)))
|
||||
}
|
||||
s.WriteString(m.spinner.Style.Render((tickCell + tickCell + tickCell)))
|
||||
} else if m.current.Failed {
|
||||
s.WriteString(m.spinner.Style.Render((crossTickCell + crossTickCell + crossTickCell)))
|
||||
}
|
||||
}
|
||||
s.WriteString("\n")
|
||||
|
||||
Reference in New Issue
Block a user