Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separating the map_args functionaliy from redis_key #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/resque-loner/unique_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ def redis_key(payload)
payload = decode(encode(payload)) # This is the cycle the data goes when being enqueued/dequeued
job = payload[:class] || payload['class']
args = (payload[:args] || payload['args'])
args.map! do |arg|
arg.is_a?(Hash) ? arg.sort : arg
end
args = map_args(args)

digest = Digest::MD5.hexdigest(encode(class: job, args: args))
Comment on lines +27 to 29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably rename the helper method encode_args, or maybe canonicalize_args, because that describes what it does instead of how it does it.

Then this would become:

Suggested change
args = map_args(args)
digest = Digest::MD5.hexdigest(encode(class: job, args: args))
digest = Digest::MD5.hexdigest(encode({ class: job, args: encode_args(args) }))

digest
end

# Separate method for easy overriding
def map_args(args)
args.map do |arg|
arg.is_a?(Hash) ? arg.sort : arg
end
end

#
# The default ttl of a locking key is -1, i.e. forever. If for some reason you only
Expand Down