Skip to content

Commit

Permalink
allow patches to work with older versions of sidekiq
Browse files Browse the repository at this point in the history
need to be able to hook into execute_job method
  • Loading branch information
Christopher Berube committed May 4, 2015
1 parent be2745a commit 852322d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/sidekiq_unique_jobs/sidekiq_test_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Worker
module ClassMethods
module Overrides
def self.included(base)
override_methods(base) unless base.method_defined?(:execute_job)

base.class_eval do
alias_method :execute_job_orig, :execute_job
alias_method :execute_job, :execute_job_ext
Expand All @@ -31,6 +33,36 @@ def clear_ext

Sidekiq.redis { |conn| conn.del(*payload_hashes) }
end

# Disable rubocop because methods are lifted directly out of Sidekiq
# rubocop:disable all
def override_methods(base)
base.class_eval do
define_method(:drain) do
while job = jobs.shift do
worker = new
worker.jid = job['jid']
execute_job(worker, job['args'])
end
end

define_method(:perform_one) do
raise(EmptyQueueError, "perform_one called with empty job queue") if jobs.empty?
job = jobs.shift
worker = new
worker.jid = job['jid']
execute_job(worker, job['args'])
end

define_method(:execute_job) do |worker, args|
worker.perform(*args)
end
end
end
# rubocop:enable all

module_function :override_methods
private_class_method :override_methods
end

include Overrides
Expand Down

0 comments on commit 852322d

Please sign in to comment.