Skip to content

Commit

Permalink
More precise lock key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
take-five committed Jun 18, 2013
1 parent 3b41525 commit 1a71f34
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/resque/integration/unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def lock_on(&block)
# LockID should be independent from MetaID
# @api private
def lock(meta_id, *args)
"lock:#{name}-#{Digest::SHA1.hexdigest(lock_on[*args].to_s)}"
"lock:#{name}-#{Digest::SHA1.hexdigest(obj_to_string(lock_on[*args]))}"
end

# Overriding +meta_id+ here so now it generates the same MetaID for Jobs with same args
Expand Down Expand Up @@ -143,7 +143,25 @@ def secret_token
::Rails.application &&
::Rails.application.config.secret_token
end
end

def obj_to_string(obj)
case obj
when Hash
s = []
obj.keys.sort.each do |k|
s << obj_to_string(k)
s << obj_to_string(obj[k])
end
s.to_s
when Array
s = []
obj.each { |a| s << obj_to_string(a) }
s.to_s
else
obj.to_s
end
end
end # module ClassMethods
end # module Unique
end # module Integration
end # module Resque

0 comments on commit 1a71f34

Please sign in to comment.