From 93ff7df4053b8d1cd0c8cd61c9365dfa8e0c2649 Mon Sep 17 00:00:00 2001 From: zekiahmetbayar Date: Wed, 8 Nov 2023 17:47:48 +0300 Subject: [PATCH] chore: Better error handling on queues --- internal/process_queue/create_report.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/process_queue/create_report.go b/internal/process_queue/create_report.go index ae928672..156b0a37 100644 --- a/internal/process_queue/create_report.go +++ b/internal/process_queue/create_report.go @@ -2,6 +2,7 @@ package process_queue import ( b64 "encoding/base64" + "encoding/json" "strings" "github.com/google/uuid" @@ -95,8 +96,27 @@ func (c CreateReport) Process() error { return err } + type limanResponse struct { + Message string `json:"message"` + Status int `json:"status"` + } + + var response limanResponse output := linux.Execute(command) - c.Queue.UpdateAsDone(strings.TrimSpace(strings.ReplaceAll(output, "\"", ""))) + if err := json.Unmarshal([]byte(output), &response); err != nil { + // Update job as failed + c.Queue.UpdateError(err.Error()) + return err + } + + if response.Status != 200 { + // Update job as failed + c.Queue.UpdateError(response.Message) + } else { + // Update job as done + c.Queue.UpdateAsDone(strings.TrimSpace(strings.ReplaceAll(output, "\"", ""))) + } + return nil }