Skip to content

Commit

Permalink
Switch to a more readable if statement than a ternary operator.
Browse files Browse the repository at this point in the history
This is also ugly and needs to be refactored.
  • Loading branch information
bryckbost committed Nov 22, 2011
1 parent 13b10d7 commit ea93223
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/delayed/backend/data_mapper.rb
Expand Up @@ -47,9 +47,11 @@ def lock_exclusively!(max_run_time, worker = worker_name)
# FIXME - this is a bit gross
# DM doesn't give us the number of rows affected by a collection update
# so we have to circumvent some niceness in DM::Collection here
collection = locked_by != worker ?
(self.class.all(:id => id, :run_at.lte => now) & (self.class.all(:locked_at => nil) | self.class.all(:locked_at.lt => now - max_run_time))) :
collection = if locked_by != worker
(self.class.all(:id => id) & (self.class.all(:locked_at => nil) | self.class.all(:locked_at.lt => now - max_run_time)) & self.class.all(:run_at.lte => now))
else
self.class.all(:id => id, :locked_by => worker)
end

attributes = collection.model.new(:locked_at => now, :locked_by => worker).dirty_attributes
affected_rows = self.repository.update(attributes, collection)
Expand Down

0 comments on commit ea93223

Please sign in to comment.