From ea93223dd1e5e78e021e7b67a107a4e1c3d25800 Mon Sep 17 00:00:00 2001 From: Brian Ryckbost Date: Tue, 22 Nov 2011 09:36:51 -0500 Subject: [PATCH] Switch to a more readable if statement than a ternary operator. This is also ugly and needs to be refactored. --- lib/delayed/backend/data_mapper.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/delayed/backend/data_mapper.rb b/lib/delayed/backend/data_mapper.rb index a056eeb..3c8a8ed 100644 --- a/lib/delayed/backend/data_mapper.rb +++ b/lib/delayed/backend/data_mapper.rb @@ -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)