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

rename redis_key to resque_loner_redis_key #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Here's how these keys are constructed:

resque:loners:queue:cache_sweeps:job:5ac5a005253450606aa9bc3b3d52ea5b
| | | |
| | | `---- Job's ID (#redis_key method)
| | | `---- Job's ID (#resque_loner_redis_key method)
| | `--------------------- Name of the queue
| `------------------------------ Prefix for this plugin
`----------------------------------------- Your redis namespace
Expand All @@ -91,15 +91,15 @@ The last part of this key is the job's ID, which is pretty much your queue item'

{ 'class': 'CacheSweeper', 'args': [1] }`

The default method to create a job ID from these parameters is to do some normalization on the payload and then md5'ing it (defined in `Resque::Plugins::UniqueJob#redis_key`).
The default method to create a job ID from these parameters is to do some normalization on the payload and then md5'ing it (defined in `Resque::Plugins::UniqueJob#resque_loner_redis_key`).

You could also use the whole payload or anything else as a redis key, as long as you make sure these requirements are met:

1. Two jobs of the same class with the same parameters/arguments/workload must produce the same redis_key
1. Two jobs of the same class with the same parameters/arguments/workload must produce the same resque_loner_redis_key
2. Two jobs with either a different class or different parameters/arguments/workloads must not produce the same redis key
3. The key must not be binary, because this restriction applies to redis keys: *Keys are not binary safe strings in Redis, but just strings not containing a space or a newline character. For instance "foo" or "123456789" or "foo_bar" are valid keys, while "hello world" or "hello\n" are not.* (see http://code.google.com/p/redis/wiki/IntroductionToRedisDataTypes)

So when your job overwrites the #redis_key method, make sure these requirements are met. And all should be good.
So when your job overwrites the #resque_loner_redis_key method, make sure these requirements are met. And all should be good.

### Resque integration

Expand Down
2 changes: 1 addition & 1 deletion lib/resque-loner/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.mark_loner_as_unqueued(queue, job)
end

def self.unique_job_queue_key(queue, item)
job_key = constantize(item[:class] || item['class']).redis_key(item)
job_key = constantize(item[:class] || item['class']).resque_loner_redis_key(item)
"loners:queue:#{queue}:job:#{job_key}"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/resque-loner/unique_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#
# If you want your job to be unique, include this module in it. If you wish,
# you can overwrite this implementation of redis_key to fit your needs
# you can overwrite this implementation of resque_loner_redis_key to fit your needs
#
module Resque
module Plugins
Expand All @@ -20,7 +20,7 @@ module ClassMethods
# Payload is what Resque stored for this job along with the job's class name.
# On a Resque with no plugins installed, this is a hash containing :class and :args
#
def redis_key(payload)
def resque_loner_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'])
Expand Down