Skip to content

Commit

Permalink
Add sidekiq 3 compatibility
Browse files Browse the repository at this point in the history
Close #34
Close #35
  • Loading branch information
mhenrixon committed Apr 28, 2014
1 parent 7e5f82c commit f992ba4
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gemfile:
- gemfiles/sidekiq_2.15.gemfile
- gemfiles/sidekiq_2.16.gemfile
- gemfiles/sidekiq_2.17.gemfile
- gemfiles/sidekiq_3.0.gemfile
- gemfiles/sidekiq_develop.gemfile
branches:
only:
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ end

appraise "sidekiq-2.15" do
gem "sidekiq", '2.15'
end

appraise "sidekiq-3.0" do
gem "sidekiq", '3.0'
end
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
gemspec

gem 'appraisal', '~> 1.0.0.beta'
gem 'appraisal', '~> 1.0.0'
gem 'pry'
gem 'pry-stack_explorer'
gem 'pry-debugger'
4 changes: 2 additions & 2 deletions gemfiles/sidekiq_2.15.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

source "http://rubygems.org"

gem "appraisal", "~> 1.0.0.beta"
gem "appraisal", "~> 1.0.0"
gem "pry"
gem "pry-stack_explorer"
gem "pry-debugger"
gem "sidekiq", "2.15"

gemspec :path=>".././"
gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/sidekiq_2.16.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

source "http://rubygems.org"

gem "appraisal", "~> 1.0.0.beta"
gem "appraisal", "~> 1.0.0"
gem "pry"
gem "pry-stack_explorer"
gem "pry-debugger"
gem "sidekiq", "2.16"

gemspec :path=>".././"
gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/sidekiq_2.17.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

source "http://rubygems.org"

gem "appraisal", "~> 1.0.0.beta"
gem "appraisal", "~> 1.0.0"
gem "pry"
gem "pry-stack_explorer"
gem "pry-debugger"
gem "sidekiq", "2.17"

gemspec :path=>".././"
gemspec :path => "../"
11 changes: 11 additions & 0 deletions gemfiles/sidekiq_3.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "appraisal", "~> 1.0.0"
gem "pry"
gem "pry-stack_explorer"
gem "pry-debugger"
gem "sidekiq", "3.0"

gemspec :path => "../"
6 changes: 3 additions & 3 deletions gemfiles/sidekiq_develop.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

source "http://rubygems.org"

gem "appraisal", "~> 1.0.0.beta"
gem "appraisal", "~> 1.0.0"
gem "pry"
gem "pry-stack_explorer"
gem "pry-debugger"
gem "sidekiq", :github=>"mperham/sidekiq"
gem "sidekiq", :github => "mperham/sidekiq"

gemspec :path=>".././"
gemspec :path => "../"
15 changes: 11 additions & 4 deletions lib/sidekiq-unique-jobs/middleware/client/unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module SidekiqUniqueJobs
module Middleware
module Client
class UniqueJobs
attr_reader :item, :worker_class
attr_reader :item, :worker_class, :redis_pool

def call(worker_class, item, queue)
def call(worker_class, item, queue, redis_pool = nil)
@redis_pool = redis_pool
@worker_class = worker_class_constantize(worker_class)
@item = item

Expand All @@ -21,8 +22,14 @@ def unique?
if testing_enabled?
unique_for_connection?(SidekiqUniqueJobs.redis_mock)
else
Sidekiq.redis do |conn|
unique_for_connection?(conn)
if redis_pool
redis_pool.with do |conn|
unique_for_connection?(conn)
end
else
Sidekiq.redis do |conn|
unique_for_connection?(conn)
end
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions lib/sidekiq-unique-jobs/middleware/server/unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ module SidekiqUniqueJobs
module Middleware
module Server
class UniqueJobs
attr_reader :unlock_order
attr_reader :unlock_order, :redis_pool

def call(worker, item, queue, redis_pool = nil)

This comment has been minimized.

Copy link
@mperham

mperham May 1, 2014

Server-side middleware does not have the same redis_pool param. This will always be nil.

This comment has been minimized.

Copy link
@mhenrixon

mhenrixon May 1, 2014

Author Owner

thanks for the note, now it won't hurt the way it is but I'll clean it up for the next version.

@redis_pool = redis_pool

def call(worker, item, queue)
set_unlock_order(worker.class)
lock_key = payload_hash(item)
unlocked = before_yield? ? unlock(lock_key).inspect : 0
Expand Down Expand Up @@ -50,7 +52,11 @@ def payload_hash(item)
end

def unlock(payload_hash)
Sidekiq.redis {|conn| conn.del(payload_hash) }
if redis_pool
redis_pool.with { |conn| conn.del(payload_hash) }
else
Sidekiq.redis { |conn| conn.del(payload_hash) }
end
end

def logger
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq-unique-jobs/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SidekiqUniqueJobs
VERSION = "2.7.1"
VERSION = "3.0.0"
end
4 changes: 2 additions & 2 deletions sidekiq-unique-jobs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Gem::Specification.new do |gem|
gem.name = "sidekiq-unique-jobs"
gem.require_paths = ["lib"]
gem.version = SidekiqUniqueJobs::VERSION
gem.add_dependency 'sidekiq', '~> 2.6'
gem.add_dependency 'sidekiq', '>= 2.6'
gem.add_dependency 'mock_redis'
gem.add_development_dependency 'rspec', '~> 3.0.0.beta'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec-sidekiq'
gem.add_development_dependency 'activesupport', '~> 3'
gem.add_development_dependency 'activesupport', '>= 3'
gem.add_development_dependency 'simplecov'
end
1 change: 1 addition & 0 deletions spec/lib/unlock_order_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'sidekiq/api'
require 'sidekiq/worker'
require 'sidekiq-unique-jobs/middleware/server/unique_jobs'

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
rescue LoadError
end

require 'rspec/autorun'
require 'rspec'

require 'celluloid/test'
Expand Down

3 comments on commit f992ba4

@mlangenberg
Copy link

Choose a reason for hiding this comment

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

Any plans on releasing a version with Sidekiq 3 compatibility?

Currently it prevents people who rely on sidekiq-unique-jobs to upgrade to Sidekiq 3.

@mhenrixon
Copy link
Owner Author

Choose a reason for hiding this comment

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

@mlangenberg - http://rubygems.org/gems/sidekiq-unique-jobs says 3.0.0 is released. Isn't that working for you?

@mlangenberg
Copy link

Choose a reason for hiding this comment

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

Thanks Mikael, I simply overlooked that. Sorry.

On GitHub I saw, latest release v2.7.0 (Nov 24, 2013): https://github.com/mhenrixon/sidekiq-unique-jobs/releases

Please sign in to comment.