Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In order to have flexiblity implement module Resque::Plugins::UniqueJob instead of old class Resque::Plugins::Loner::UniqueJob remained with deprecation warning.
- Loading branch information
Showing
5 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,54 @@ | ||
require 'digest/md5' | ||
|
||
# | ||
# If you want your job to be unique, subclass it from this class. If you wish, | ||
# 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 | ||
# | ||
module Resque | ||
module Plugins | ||
module Loner | ||
class UniqueJob | ||
extend Resque::Helpers | ||
module UniqueJob | ||
|
||
def self.included(base) | ||
base.extend ClassMethods | ||
base.class_eval do | ||
base.send(:extend, Resque::Helpers) | ||
end | ||
end # self.included | ||
|
||
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 self.redis_key(payload) | ||
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"] | ||
digest = Digest::MD5.hexdigest encode(:class => job, :args => args) | ||
digest | ||
end | ||
end # ClassMethods | ||
|
||
|
||
end | ||
end | ||
end | ||
module Resque | ||
module Plugins | ||
module Loner | ||
class UniqueJob | ||
|
||
include Resque::Plugins::UniqueJob | ||
|
||
def self.inherited(host) | ||
super(host) | ||
return if @__unique_job_warned | ||
warn "Inherit Resque::Plugins::Loner::UniqueJob is deprecated. Include Resque::Plugins::UniqueJob module instead." | ||
@__unique_job_warned = true | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters