sidekiq-unique-jobs 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq-unique-jobs might be problematic. Click here for more details.

data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+
2
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v2.1.0
2
+
3
+ Extracted the unique jobs portion from sidekiq main repo since @mperham dropped support for it.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'celluloid'
5
+ gem 'slim'
6
+ gem 'sprockets'
7
+ gem 'sass'
8
+ gem 'rails', '3.2.6'
9
+ gem 'sqlite3'
10
+
11
+ group :test do
12
+ gem 'simplecov', :require => false
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sidekiq-unique-jobs (2.1.0)
5
+ sidekiq (~> 2.1.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.6)
11
+ actionpack (= 3.2.6)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.6)
14
+ activemodel (= 3.2.6)
15
+ activesupport (= 3.2.6)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.1)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.1.3)
23
+ activemodel (3.2.6)
24
+ activesupport (= 3.2.6)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.6)
27
+ activemodel (= 3.2.6)
28
+ activesupport (= 3.2.6)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.6)
32
+ activemodel (= 3.2.6)
33
+ activesupport (= 3.2.6)
34
+ activesupport (3.2.6)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.0)
39
+ celluloid (0.11.1)
40
+ timers (>= 1.0.0)
41
+ connection_pool (0.9.2)
42
+ erubis (2.7.0)
43
+ hike (1.2.1)
44
+ i18n (0.6.0)
45
+ journey (1.0.4)
46
+ json (1.7.3)
47
+ mail (2.4.4)
48
+ i18n (>= 0.4.0)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ mime-types (1.19)
52
+ minitest (3.2.0)
53
+ multi_json (1.3.6)
54
+ polyglot (0.3.3)
55
+ rack (1.4.1)
56
+ rack-cache (1.2)
57
+ rack (>= 0.4)
58
+ rack-protection (1.2.0)
59
+ rack
60
+ rack-ssl (1.3.2)
61
+ rack
62
+ rack-test (0.6.1)
63
+ rack (>= 1.0)
64
+ rails (3.2.6)
65
+ actionmailer (= 3.2.6)
66
+ actionpack (= 3.2.6)
67
+ activerecord (= 3.2.6)
68
+ activeresource (= 3.2.6)
69
+ activesupport (= 3.2.6)
70
+ bundler (~> 1.0)
71
+ railties (= 3.2.6)
72
+ railties (3.2.6)
73
+ actionpack (= 3.2.6)
74
+ activesupport (= 3.2.6)
75
+ rack-ssl (~> 1.3.2)
76
+ rake (>= 0.8.7)
77
+ rdoc (~> 3.4)
78
+ thor (>= 0.14.6, < 2.0)
79
+ rake (0.9.2.2)
80
+ rdoc (3.12)
81
+ json (~> 1.4)
82
+ redis (3.0.1)
83
+ redis-namespace (1.2.0)
84
+ redis (~> 3.0.0)
85
+ sass (3.1.20)
86
+ sidekiq (2.1.0)
87
+ celluloid (~> 0.11.1)
88
+ connection_pool (~> 0.9.2)
89
+ multi_json (~> 1)
90
+ redis (~> 3)
91
+ redis-namespace
92
+ simplecov (0.6.4)
93
+ multi_json (~> 1.0)
94
+ simplecov-html (~> 0.5.3)
95
+ simplecov-html (0.5.3)
96
+ sinatra (1.3.2)
97
+ rack (~> 1.3, >= 1.3.6)
98
+ rack-protection (~> 1.2)
99
+ tilt (~> 1.3, >= 1.3.3)
100
+ slim (1.2.2)
101
+ temple (~> 0.4.0)
102
+ tilt (~> 1.3.3)
103
+ sprockets (2.1.3)
104
+ hike (~> 1.2)
105
+ rack (~> 1.0)
106
+ tilt (~> 1.1, != 1.3.0)
107
+ sqlite3 (1.3.6)
108
+ temple (0.4.0)
109
+ thor (0.15.4)
110
+ tilt (1.3.3)
111
+ timers (1.0.1)
112
+ treetop (1.4.10)
113
+ polyglot
114
+ polyglot (>= 0.3.1)
115
+ tzinfo (0.3.33)
116
+
117
+ PLATFORMS
118
+ ruby
119
+
120
+ DEPENDENCIES
121
+ actionmailer (~> 3)
122
+ activerecord (~> 3)
123
+ celluloid
124
+ minitest (~> 3)
125
+ rails (= 3.2.6)
126
+ rake
127
+ sass
128
+ sidekiq-unique-jobs!
129
+ simplecov
130
+ sinatra
131
+ slim
132
+ sprockets
133
+ sqlite3
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mikael Henriksson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # SidekiqUniqueJobs
2
+
3
+ The missing unique jobs for sidekiq
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sidekiq-unique-jobs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sidekiq-unique-jobs
18
+
19
+ ## Usage
20
+
21
+ All that is required is that you specifically set the sidekiq option for *unique* to true like below:
22
+
23
+ ```ruby
24
+ sidekiq_options unique: true
25
+ ```
26
+
27
+ Requiring the gem in your gemfile should be sufficient to enable unique jobs.
28
+
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'test'
6
+ #SO MUCH NOISE
7
+ #test.warning = true
8
+ test.pattern = 'test/**/test_*.rb'
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require 'sidekiq-unique-jobs/middleware'
2
+ require "sidekiq-unique-jobs/version"
@@ -0,0 +1,16 @@
1
+ require 'sidekiq/middleware/chain'
2
+ require 'sidekiq/processor'
3
+
4
+ Sidekiq.configure_server do |config|
5
+ config.server_middleware do |chain|
6
+ require 'sidekiq-unique-jobs/middleware/server/unique_jobs'
7
+ chain.add SidekiqUniqueJobs::Middleware::Server::UniqueJobs
8
+ end
9
+ end
10
+
11
+ Sidekiq.configure_client do |config|
12
+ config.client_middleware do |chain|
13
+ require 'sidekiq-unique-jobs/middleware/client/unique_jobs'
14
+ chain.add SidekiqUniqueJobs::Middleware::Client::UniqueJobs
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'digest'
2
+
3
+ module SidekiqUniqueJobs
4
+ module Middleware
5
+ module Client
6
+ class UniqueJobs
7
+ HASH_KEY_EXPIRATION = 30 * 60
8
+
9
+ def call(worker_class, item, queue)
10
+ enabled = worker_class.get_sidekiq_options['unique']
11
+ if enabled
12
+ payload_hash = Digest::MD5.hexdigest(Sidekiq.dump_json(item))
13
+ unique = false
14
+
15
+ Sidekiq.redis do |conn|
16
+ conn.watch(payload_hash)
17
+
18
+ if conn.get(payload_hash)
19
+ conn.unwatch
20
+ else
21
+ unique = conn.multi do
22
+ conn.setex(payload_hash, HASH_KEY_EXPIRATION, 1)
23
+ end
24
+ end
25
+ end
26
+ yield if unique
27
+ else
28
+ yield
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ require 'digest'
2
+
3
+ module SidekiqUniqueJobs
4
+ module Middleware
5
+ module Server
6
+ class UniqueJobs
7
+ def call(*args)
8
+ yield
9
+ ensure
10
+ json = Sidekiq.dump_json(args[1])
11
+ hash = Digest::MD5.hexdigest(json)
12
+ Sidekiq.redis {|conn| conn.del(hash) }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module SidekiqUniqueJobs
2
+ VERSION = "2.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sidekiq-unique-jobs/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Mikael Henriksson"]
6
+ gem.email = ["mikael@zoolutions.se"]
7
+ gem.description = gem.summary = "The unique jobs that were removed from sidekiq"
8
+ gem.homepage = "http://mperham.github.com/sidekiq"
9
+ gem.license = "LGPL-3.0"
10
+
11
+ # gem.executables = ['']
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- test/*`.split("\n")
14
+ gem.name = "sidekiq-unique-jobs"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SidekiqUniqueJobs::VERSION
17
+ gem.add_dependency 'sidekiq', '~> 2.1.0'
18
+ gem.add_development_dependency 'minitest', '~> 3'
19
+ gem.add_development_dependency 'sinatra'
20
+ gem.add_development_dependency 'slim'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'actionmailer', '~> 3'
23
+ gem.add_development_dependency 'activerecord', '~> 3'
24
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
2
+ if ENV.has_key?("SIMPLECOV")
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ end
6
+
7
+ require 'minitest/unit'
8
+ require 'minitest/pride'
9
+ require 'minitest/autorun'
10
+
11
+ require 'sidekiq-unique-jobs'
12
+ require "sidekiq"
13
+ require 'sidekiq/util'
14
+ Sidekiq.logger.level = Logger::ERROR
15
+
16
+ require 'sidekiq/redis_connection'
17
+ REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'testy')
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+ require 'sidekiq/worker'
3
+ require "sidekiq-unique-jobs"
4
+
5
+ class TestClient < MiniTest::Unit::TestCase
6
+ describe 'with real redis' do
7
+ before do
8
+ Sidekiq.redis = REDIS
9
+ Sidekiq.redis {|c| c.flushdb }
10
+ end
11
+
12
+ class QueueWorker
13
+ include Sidekiq::Worker
14
+ sidekiq_options :queue => 'customqueue'
15
+ end
16
+
17
+ it 'does not push duplicate messages when configured for unique only' do
18
+ QueueWorker.sidekiq_options :unique => true
19
+ 10.times { Sidekiq::Client.push('class' => QueueWorker, 'args' => [1, 2]) }
20
+ assert_equal 1, Sidekiq.redis {|c| c.llen("queue:customqueue") }
21
+ end
22
+
23
+ it 'does push duplicate messages when not configured for unique only' do
24
+ QueueWorker.sidekiq_options :unique => false
25
+ 10.times { Sidekiq::Client.push('class' => QueueWorker, 'args' => [1, 2]) }
26
+ assert_equal 10, Sidekiq.redis {|c| c.llen("queue:customqueue") }
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-unique-jobs
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mikael Henriksson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sinatra
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: slim
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: actionmailer
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '3'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3'
110
+ - !ruby/object:Gem::Dependency
111
+ name: activerecord
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '3'
126
+ description: The unique jobs that were removed from sidekiq
127
+ email:
128
+ - mikael@zoolutions.se
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - CHANGELOG.md
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - lib/sidekiq-unique-jobs.rb
141
+ - lib/sidekiq-unique-jobs/middleware.rb
142
+ - lib/sidekiq-unique-jobs/middleware/client/unique_jobs.rb
143
+ - lib/sidekiq-unique-jobs/middleware/server/unique_jobs.rb
144
+ - lib/sidekiq-unique-jobs/version.rb
145
+ - sidekiq-unique-jobs.gemspec
146
+ - test/helper.rb
147
+ - test/lib/sidekiq/test_client.rb
148
+ homepage: http://mperham.github.com/sidekiq
149
+ licenses:
150
+ - LGPL-3.0
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ segments:
162
+ - 0
163
+ hash: -2446112843822293648
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ segments:
171
+ - 0
172
+ hash: -2446112843822293648
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.24
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: The unique jobs that were removed from sidekiq
179
+ test_files:
180
+ - test/helper.rb
181
+ - test/lib/sidekiq/test_client.rb