@@ -66,6 +66,7 @@ EXAMPLES:
66
66
type batchListMessage struct {
67
67
Status string `json:"status"`
68
68
Jobs []madmin.BatchJobResult `json:"jobs"`
69
+ Admin * madmin.AdminClient `json:"-"` // Add AdminClient to fetch job status
69
70
}
70
71
71
72
// String colorized batchList message
@@ -90,15 +91,35 @@ func (c batchListMessage) String() string {
90
91
table .SetTablePadding ("\t " ) // pad with tabs
91
92
table .SetNoWhiteSpace (true )
92
93
93
- table .SetHeader ([]string {"ID" , "TYPE" , "USER" , "STARTED" })
94
- data := make ([][]string , 0 , 4 )
94
+ // Add a new "STATUS" column to the table header
95
+ table .SetHeader ([]string {"ID" , "TYPE" , "USER" , "STARTED" , "STATUS" })
96
+ data := make ([][]string , 0 , 5 )
95
97
98
+ // Fetch the status for the batch job using BatchJobStatus API
96
99
for _ , job := range c .Jobs {
100
+ jobStatus := "unknown"
101
+ jobMetric , err := c .Admin .BatchJobStatus (context .Background (), job .ID )
102
+
103
+ // Output error if the API call fails, but continue processing remaining jobs
104
+ if err != nil {
105
+ println ("Failed to fetch job status for Job ID:" , job .ID , "Error:" , err .Error ())
106
+ } else {
107
+ if jobMetric .LastMetric .Complete && ! jobMetric .LastMetric .Failed {
108
+ jobStatus = "completed"
109
+ } else if ! jobMetric .LastMetric .Complete && ! jobMetric .LastMetric .Failed {
110
+ jobStatus = "in-progress"
111
+ } else if jobMetric .LastMetric .Failed {
112
+ jobStatus = "failed"
113
+ }
114
+ }
115
+
116
+ // Add jobStatus details to the data table
97
117
data = append (data , []string {
98
118
job .ID ,
99
119
string (job .Type ),
100
120
job .User ,
101
121
humanize .Time (job .Started ),
122
+ jobStatus ,
102
123
})
103
124
}
104
125
@@ -111,7 +132,43 @@ func (c batchListMessage) String() string {
111
132
// JSON jsonified batchList message
112
133
func (c batchListMessage ) JSON () string {
113
134
c .Status = "success"
114
- batchListMessageBytes , e := json .MarshalIndent (c , "" , " " )
135
+
136
+ // Create a temporary slice to hold jobs with derived statuses
137
+ jobsWithStatus := make ([]map [string ]interface {}, len (c .Jobs ))
138
+
139
+ // Fetch the status for the batch job using BatchJobStatus API
140
+ for i , job := range c .Jobs {
141
+ jobStatus := "unknown"
142
+ jobMetric , err := c .Admin .BatchJobStatus (context .Background (), job .ID )
143
+
144
+ // Output error if the API call fails, but continue processing remaining jobs
145
+ if err != nil {
146
+ println ("Failed to fetch job status for Job ID:" , job .ID , "Error:" , err .Error ())
147
+ } else {
148
+ if jobMetric .LastMetric .Complete && ! jobMetric .LastMetric .Failed {
149
+ jobStatus = "completed"
150
+ } else if ! jobMetric .LastMetric .Complete && ! jobMetric .LastMetric .Failed {
151
+ jobStatus = "in-progress"
152
+ } else if jobMetric .LastMetric .Failed {
153
+ jobStatus = "failed"
154
+ }
155
+ }
156
+
157
+ // Add the job details along with the derived status
158
+ jobsWithStatus [i ] = map [string ]interface {}{
159
+ "id" : job .ID ,
160
+ "type" : job .Type ,
161
+ "user" : job .User ,
162
+ "started" : job .Started ,
163
+ "status" : jobStatus ,
164
+ }
165
+ }
166
+
167
+ // Marshal the updated jobs into JSON
168
+ batchListMessageBytes , e := json .MarshalIndent (map [string ]interface {}{
169
+ "status" : c .Status ,
170
+ "jobs" : jobsWithStatus ,
171
+ }, "" , " " )
115
172
fatalIf (probe .NewError (e ), "Unable to marshal into JSON." )
116
173
117
174
return string (batchListMessageBytes )
@@ -147,6 +204,7 @@ func mainBatchList(ctx *cli.Context) error {
147
204
printMsg (batchListMessage {
148
205
Status : "success" ,
149
206
Jobs : res .Jobs ,
207
+ Admin : adminClient , // Pass the adminClient for status lookups
150
208
})
151
209
return nil
152
210
}
0 commit comments