feat: Changes task errors to string array
This commit is contained in:
15
handler.go
15
handler.go
@@ -22,6 +22,7 @@ func (s *Server) handleEnqueue(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
var req struct {
|
||||
ApplicationId string `json:"applicationId"`
|
||||
EventId string `json:"eventId"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
Priority int `json:"priority"`
|
||||
DelaySec int `json:"delaySec"` // optional delay until available
|
||||
@@ -42,6 +43,7 @@ func (s *Server) handleEnqueue(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
task := models.Task{
|
||||
ApplicationId: req.ApplicationId,
|
||||
EventId: req.EventId,
|
||||
Payload: req.Payload,
|
||||
Priority: req.Priority,
|
||||
AvailableAt: availableAt,
|
||||
@@ -150,10 +152,11 @@ func (s *Server) handlePop(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// If attempts > maxAttempts, mark done with error note instead of returning
|
||||
if task.MaxAttempts > 0 && task.Attempts > task.MaxAttempts {
|
||||
task.Errors = append(task.Errors, "max retry attempts exceeded")
|
||||
_, _ = s.col.UpdateByID(ctx, task.ID, bson.D{
|
||||
{"$set", bson.D{
|
||||
{"status", StatusDone},
|
||||
{"error", "max attempts exceeded"},
|
||||
{"errors", task.Errors},
|
||||
{"updatedAt", time.Now().UTC()},
|
||||
}},
|
||||
})
|
||||
@@ -277,10 +280,10 @@ func (s *Server) handleRequeue(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
var req struct {
|
||||
TaskID string `json:"taskId"`
|
||||
WorkerID string `json:"workerId"`
|
||||
DelaySec int `json:"delaySec"` // optional
|
||||
Error string `json:"error"`
|
||||
TaskID string `json:"taskId"`
|
||||
WorkerID string `json:"workerId"`
|
||||
DelaySec int `json:"delaySec"` // optional
|
||||
Errors []string `json:"errors"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
httpError(w, http.StatusBadRequest, "invalid json: "+err.Error())
|
||||
@@ -318,7 +321,7 @@ func (s *Server) handleRequeue(w http.ResponseWriter, r *http.Request) {
|
||||
{"leaseOwner", ""},
|
||||
{"leasedUntil", time.Time{}},
|
||||
{"updatedAt", now},
|
||||
{"error", req.Error},
|
||||
{"errors", req.Errors},
|
||||
}},
|
||||
}
|
||||
res, err := s.col.UpdateOne(ctx, filter, update)
|
||||
|
||||
Reference in New Issue
Block a user