From 387c642402ef584d4a02977e07d32b98de541b40 Mon Sep 17 00:00:00 2001 From: mrhid6 Date: Mon, 29 Dec 2025 11:04:28 +0000 Subject: [PATCH] feat: Changes task errors to string array --- handler.go | 15 +++++++++------ models/task.go | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/handler.go b/handler.go index 3e55b74..ca57df5 100755 --- a/handler.go +++ b/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) diff --git a/models/task.go b/models/task.go index 2d53792..21ba619 100755 --- a/models/task.go +++ b/models/task.go @@ -20,5 +20,5 @@ type Task struct { MaxAttempts int `bson:"maxAttempts,omitempty" json:"maxAttempts"` CreatedAt time.Time `bson:"createdAt,omitempty" json:"createdAt"` UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"` - Error string `bson:"error,omitempty" json:"error,omitempty"` + Errors []string `bson:"errors,omitempty" json:"errors,omitempty"` }