mirror of
https://github.com/hibiken/asynq.git
synced 2025-08-19 15:08:55 +08:00
Record last_failed_at time on Retry or Archive event
This commit is contained in:
@@ -483,14 +483,15 @@ return redis.status_reply("OK")`)
|
||||
// and assigning error message to the task message.
|
||||
func (r *RDB) Retry(msg *base.TaskMessage, processAt time.Time, errMsg string) error {
|
||||
var op errors.Op = "rdb.Retry"
|
||||
now := time.Now()
|
||||
modified := *msg
|
||||
modified.Retried++
|
||||
modified.ErrorMsg = errMsg
|
||||
modified.LastFailedAt = now.Unix()
|
||||
encoded, err := base.EncodeMessage(&modified)
|
||||
if err != nil {
|
||||
return errors.E(op, errors.Internal, fmt.Sprintf("cannot encode message: %v", err))
|
||||
}
|
||||
now := time.Now()
|
||||
expireAt := now.Add(statsTTL)
|
||||
keys := []string{
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
@@ -551,13 +552,14 @@ return redis.status_reply("OK")`)
|
||||
// It also trims the archive by timestamp and set size.
|
||||
func (r *RDB) Archive(msg *base.TaskMessage, errMsg string) error {
|
||||
var op errors.Op = "rdb.Archive"
|
||||
now := time.Now()
|
||||
modified := *msg
|
||||
modified.ErrorMsg = errMsg
|
||||
modified.LastFailedAt = now.Unix()
|
||||
encoded, err := base.EncodeMessage(&modified)
|
||||
if err != nil {
|
||||
return errors.E(op, errors.Internal, fmt.Sprintf("cannot encode message: %v", err))
|
||||
}
|
||||
now := time.Now()
|
||||
cutoff := now.AddDate(0, 0, -archivedExpirationInDays)
|
||||
expireAt := now.Add(statsTTL)
|
||||
keys := []string{
|
||||
|
@@ -1163,9 +1163,13 @@ func TestRetry(t *testing.T) {
|
||||
t.Errorf("mismatch found in %q; (-want, +got)\n%s", base.DeadlinesKey(queue), diff)
|
||||
}
|
||||
}
|
||||
cmpOpts := []cmp.Option{
|
||||
h.SortZSetEntryOpt,
|
||||
cmpopts.EquateApproxTime(5 * time.Second), // for LastFailedAt field
|
||||
}
|
||||
for queue, want := range tc.wantRetry {
|
||||
gotRetry := h.GetRetryEntries(t, r.client, queue)
|
||||
if diff := cmp.Diff(want, gotRetry, h.SortZSetEntryOpt); diff != "" {
|
||||
if diff := cmp.Diff(want, gotRetry, cmpOpts...); diff != "" {
|
||||
t.Errorf("mismatch found in %q; (-want, +got)\n%s", base.RetryKey(queue), diff)
|
||||
}
|
||||
}
|
||||
@@ -1368,7 +1372,7 @@ func TestArchive(t *testing.T) {
|
||||
}
|
||||
for queue, want := range tc.wantArchived {
|
||||
gotArchived := h.GetArchivedEntries(t, r.client, queue)
|
||||
if diff := cmp.Diff(want, gotArchived, h.SortZSetEntryOpt, zScoreCmpOpt); diff != "" {
|
||||
if diff := cmp.Diff(want, gotArchived, h.SortZSetEntryOpt, zScoreCmpOpt, timeCmpOpt); diff != "" {
|
||||
t.Errorf("mismatch found in %q after calling (*RDB).Archive: (-want, +got):\n%s", base.ArchivedKey(queue), diff)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user