Skip to content

Commit 93ff7df

Browse files
chore: Better error handling on queues
1 parent 6311840 commit 93ff7df

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

internal/process_queue/create_report.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package process_queue
22

33
import (
44
b64 "encoding/base64"
5+
"encoding/json"
56
"strings"
67

78
"github.com/google/uuid"
@@ -95,8 +96,27 @@ func (c CreateReport) Process() error {
9596
return err
9697
}
9798

99+
type limanResponse struct {
100+
Message string `json:"message"`
101+
Status int `json:"status"`
102+
}
103+
104+
var response limanResponse
98105
output := linux.Execute(command)
99106

100-
c.Queue.UpdateAsDone(strings.TrimSpace(strings.ReplaceAll(output, "\"", "")))
107+
if err := json.Unmarshal([]byte(output), &response); err != nil {
108+
// Update job as failed
109+
c.Queue.UpdateError(err.Error())
110+
return err
111+
}
112+
113+
if response.Status != 200 {
114+
// Update job as failed
115+
c.Queue.UpdateError(response.Message)
116+
} else {
117+
// Update job as done
118+
c.Queue.UpdateAsDone(strings.TrimSpace(strings.ReplaceAll(output, "\"", "")))
119+
}
120+
101121
return nil
102122
}

0 commit comments

Comments
 (0)