Skip to content

Commit

Permalink
Fix rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields committed Apr 3, 2021
1 parent f6cd2e5 commit 7d10bdf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/delayed/backend/mongoid.rb
Expand Up @@ -29,7 +29,6 @@ def reload(*args)
end

class << self

def db_time_now
Time.now.utc
end
Expand All @@ -40,8 +39,8 @@ def reserve(worker, max_run_time = Worker.max_run_time)
right_now = db_time_now
criteria = reservation_criteria(worker, right_now, max_run_time)
criteria.find_one_and_update(
{ '$set' => { locked_at: right_now, locked_by: worker.name } },
return_document: :after
{ '$set' => { locked_at: right_now, locked_by: worker.name } },
return_document: :after
)
end

Expand Down Expand Up @@ -71,12 +70,12 @@ def after_fork
# Jobs are sorted by priority and run_at.
def reservation_criteria(worker, right_now, max_run_time)
criteria = where(
run_at: { '$lte' => right_now },
failed_at: nil
run_at: { '$lte' => right_now },
failed_at: nil
).any_of(
{ locked_by: worker.name },
{ locked_at: nil },
locked_at: { '$lt' => (right_now - max_run_time) }
{ locked_by: worker.name },
{ locked_at: nil },
locked_at: { '$lt' => (right_now - max_run_time) }
)

criteria = criteria.gte(priority: Worker.min_priority.to_i) if Worker.min_priority
Expand Down

0 comments on commit 7d10bdf

Please sign in to comment.