Skip to content

Commit

Permalink
Inline
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed Mar 11, 2024
1 parent 6ea4707 commit b45edfd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/delayed/backend/modern_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ def self.clear_locks!(worker_name)
end

def self.reserve(worker, max_run_time = Worker.max_run_time)
ready_scope = ready_to_run(worker.name, max_run_time).min_priority.max_priority.for_queues.by_priority

now = db_time_now.change(usec: 0)
count = ready_scope.limit(1).update_all(locked_at: now, locked_by: worker.name)
count =
ready_to_run(worker.name, max_run_time)
.min_priority
.max_priority
.for_queues
.by_priority
.limit(1)
.update_all(locked_at: now, locked_by: worker.name)
return if count == 0

where(locked_at: now, locked_by: worker.name, failed_at: nil).first
Expand Down

0 comments on commit b45edfd

Please sign in to comment.