From 7b953ec22ee7f40997f838274a5119312388b914 Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Fri, 3 May 2024 15:48:52 +0100 Subject: [PATCH] Add batch status job API Currently, the status is based on metrics API, but a simple restart of a node after a successful batch will lose that information. --- batch-job.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/batch-job.go b/batch-job.go index 1390c2b7..a96d33ed 100644 --- a/batch-job.go +++ b/batch-job.go @@ -225,6 +225,39 @@ func (adm *AdminClient) StartBatchJob(ctx context.Context, job string) (BatchJob return res, nil } +// BatchJobStatus contains the last batch job metric +type BatchJobStatus struct { + LastMetric JobMetric +} + +// BatchJobStatus returns the status of the given job. +func (adm *AdminClient) BatchJobStatus(ctx context.Context, jobID string) (BatchJobStatus, error) { + values := make(url.Values) + values.Set("jobId", jobID) + + resp, err := adm.executeMethod(ctx, http.MethodGet, + requestData{ + relPath: adminAPIPrefix + "/status-job", + queryValues: values, + }, + ) + if err != nil { + return BatchJobStatus{}, err + } + defer closeResponse(resp) + if resp.StatusCode != http.StatusOK { + return BatchJobStatus{}, httpRespToErrorResponse(resp) + } + + res := BatchJobStatus{} + dec := json.NewDecoder(resp.Body) + if err = dec.Decode(&res); err != nil { + return res, err + } + + return res, nil +} + // DescribeBatchJob - describes a currently running Job. func (adm *AdminClient) DescribeBatchJob(ctx context.Context, jobID string) (string, error) { values := make(url.Values)