Skip to content

Commit

Permalink
chore: Better error handling on queues
Browse files Browse the repository at this point in the history
  • Loading branch information
zekiahmetbayar committed Nov 8, 2023
1 parent 6311840 commit 93ff7df
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/process_queue/create_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package process_queue

import (
b64 "encoding/base64"
"encoding/json"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -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
}

0 comments on commit 93ff7df

Please sign in to comment.