From 4d2e0198f37870ba93a84d243024f16448525c59 Mon Sep 17 00:00:00 2001 From: Egor Matveev Date: Sun, 23 Mar 2025 11:30:46 +0300 Subject: [PATCH] fix --- app/storage/mongo/collections/tasks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/storage/mongo/collections/tasks.go b/app/storage/mongo/collections/tasks.go index 2a29c7f..05c521c 100644 --- a/app/storage/mongo/collections/tasks.go +++ b/app/storage/mongo/collections/tasks.go @@ -71,7 +71,7 @@ func Take(queue string) (*Task, error) { "taken_at": now, "attempts": task.Attempts + 1, "available_from": now.Add( - time.Duration(task.SecondsToExecute) * time.Second, + time.Duration(task.SecondsToExecute+task.Attempts) * time.Second, ), }, }, @@ -91,7 +91,7 @@ func findTask(queue string, now time.Time) (*Task, error) { "queue": queue, "available_from": bson.M{"$lte": now}, }, - options.Find().SetLimit(1), + options.Find().SetSort(bson.D{{Key: "available_from", Value: 1}}).SetLimit(1), ) if err != nil { println("Error find")