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 {
|
var req struct {
|
||||||
ApplicationId string `json:"applicationId"`
|
ApplicationId string `json:"applicationId"`
|
||||||
|
EventId string `json:"eventId"`
|
||||||
Payload map[string]interface{} `json:"payload"`
|
Payload map[string]interface{} `json:"payload"`
|
||||||
Priority int `json:"priority"`
|
Priority int `json:"priority"`
|
||||||
DelaySec int `json:"delaySec"` // optional delay until available
|
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{
|
task := models.Task{
|
||||||
ApplicationId: req.ApplicationId,
|
ApplicationId: req.ApplicationId,
|
||||||
|
EventId: req.EventId,
|
||||||
Payload: req.Payload,
|
Payload: req.Payload,
|
||||||
Priority: req.Priority,
|
Priority: req.Priority,
|
||||||
AvailableAt: availableAt,
|
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 attempts > maxAttempts, mark done with error note instead of returning
|
||||||
if task.MaxAttempts > 0 && task.Attempts > task.MaxAttempts {
|
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{
|
_, _ = s.col.UpdateByID(ctx, task.ID, bson.D{
|
||||||
{"$set", bson.D{
|
{"$set", bson.D{
|
||||||
{"status", StatusDone},
|
{"status", StatusDone},
|
||||||
{"error", "max attempts exceeded"},
|
{"errors", task.Errors},
|
||||||
{"updatedAt", time.Now().UTC()},
|
{"updatedAt", time.Now().UTC()},
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
@@ -277,10 +280,10 @@ func (s *Server) handleRequeue(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var req struct {
|
var req struct {
|
||||||
TaskID string `json:"taskId"`
|
TaskID string `json:"taskId"`
|
||||||
WorkerID string `json:"workerId"`
|
WorkerID string `json:"workerId"`
|
||||||
DelaySec int `json:"delaySec"` // optional
|
DelaySec int `json:"delaySec"` // optional
|
||||||
Error string `json:"error"`
|
Errors []string `json:"errors"`
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "invalid json: "+err.Error())
|
httpError(w, http.StatusBadRequest, "invalid json: "+err.Error())
|
||||||
@@ -318,7 +321,7 @@ func (s *Server) handleRequeue(w http.ResponseWriter, r *http.Request) {
|
|||||||
{"leaseOwner", ""},
|
{"leaseOwner", ""},
|
||||||
{"leasedUntil", time.Time{}},
|
{"leasedUntil", time.Time{}},
|
||||||
{"updatedAt", now},
|
{"updatedAt", now},
|
||||||
{"error", req.Error},
|
{"errors", req.Errors},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
res, err := s.col.UpdateOne(ctx, filter, update)
|
res, err := s.col.UpdateOne(ctx, filter, update)
|
||||||
|
|||||||
@@ -20,5 +20,5 @@ type Task struct {
|
|||||||
MaxAttempts int `bson:"maxAttempts,omitempty" json:"maxAttempts"`
|
MaxAttempts int `bson:"maxAttempts,omitempty" json:"maxAttempts"`
|
||||||
CreatedAt time.Time `bson:"createdAt,omitempty" json:"createdAt"`
|
CreatedAt time.Time `bson:"createdAt,omitempty" json:"createdAt"`
|
||||||
UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"`
|
UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"`
|
||||||
Error string `bson:"error,omitempty" json:"error,omitempty"`
|
Errors []string `bson:"errors,omitempty" json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user