sidekiq 0.6.0 → 0.7.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 might be problematic. Click here for more details.

Files changed (45) hide show
  1. data/.travis.yml +3 -0
  2. data/Changes.md +15 -0
  3. data/README.md +1 -1
  4. data/TODO.md +0 -2
  5. data/examples/chef/cookbooks/sidekiq/README.rdoc +7 -0
  6. data/examples/chef/cookbooks/sidekiq/recipes/default.rb +54 -0
  7. data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +8 -0
  8. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +219 -0
  9. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +28 -0
  10. data/examples/monitrc.conf +6 -0
  11. data/examples/por.rb +10 -0
  12. data/lib/sidekiq.rb +70 -0
  13. data/lib/sidekiq/cli.rb +72 -30
  14. data/lib/sidekiq/client.rb +16 -16
  15. data/lib/sidekiq/extensions/action_mailer.rb +27 -0
  16. data/lib/sidekiq/extensions/active_record.rb +29 -0
  17. data/lib/sidekiq/extensions/generic_proxy.rb +21 -0
  18. data/lib/sidekiq/manager.rb +16 -12
  19. data/lib/sidekiq/middleware/chain.rb +23 -23
  20. data/lib/sidekiq/middleware/client/resque_web_compatibility.rb +1 -4
  21. data/lib/sidekiq/middleware/client/unique_jobs.rb +5 -13
  22. data/lib/sidekiq/middleware/server/failure_jobs.rb +24 -0
  23. data/lib/sidekiq/middleware/server/unique_jobs.rb +1 -5
  24. data/lib/sidekiq/processor.rb +11 -13
  25. data/lib/sidekiq/redis_connection.rb +1 -1
  26. data/lib/sidekiq/util.rb +20 -1
  27. data/lib/sidekiq/version.rb +1 -1
  28. data/lib/sidekiq/worker.rb +1 -1
  29. data/myapp/Gemfile +0 -2
  30. data/myapp/app/controllers/work_controller.rb +25 -1
  31. data/myapp/app/mailers/user_mailer.rb +9 -0
  32. data/myapp/app/models/post.rb +3 -0
  33. data/myapp/app/views/user_mailer/greetings.html.erb +3 -0
  34. data/myapp/app/workers/hard_worker.rb +2 -2
  35. data/myapp/config/initializers/sidekiq.rb +6 -1
  36. data/myapp/config/routes.rb +3 -0
  37. data/sidekiq.gemspec +2 -0
  38. data/test/config.yml +11 -0
  39. data/test/test_cli.rb +119 -3
  40. data/test/test_client.rb +21 -10
  41. data/test/test_extensions.rb +45 -0
  42. data/test/test_manager.rb +2 -2
  43. data/test/test_middleware.rb +7 -12
  44. data/test/test_stats.rb +1 -2
  45. metadata +55 -16
data/test/test_client.rb CHANGED
@@ -5,24 +5,24 @@ require 'sidekiq/worker'
5
5
  class TestClient < MiniTest::Unit::TestCase
6
6
  describe 'with real redis' do
7
7
  before do
8
- Sidekiq::Client.redis = Redis.connect(:url => 'redis://localhost/sidekiq_test')
9
- Sidekiq::Client.redis.flushdb
8
+ Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
9
+ Sidekiq.redis.flushdb
10
10
  end
11
11
 
12
12
  it 'does not push duplicate messages when configured for unique only' do
13
- Sidekiq::Client.middleware.entries.clear
14
- Sidekiq::Client.middleware.register do
15
- use Sidekiq::Middleware::Client::UniqueJobs, Sidekiq::Client.redis
16
- use Sidekiq::Middleware::Client::ResqueWebCompatibility, Sidekiq::Client.redis
13
+ Sidekiq.client_middleware.entries.clear
14
+ Sidekiq.client_middleware do |chain|
15
+ chain.add Sidekiq::Middleware::Client::UniqueJobs
16
+ chain.add Sidekiq::Middleware::Client::ResqueWebCompatibility
17
17
  end
18
18
  10.times { Sidekiq::Client.push('customqueue', 'class' => 'Foo', 'args' => [1, 2]) }
19
- assert_equal 1, Sidekiq::Client.redis.llen("queue:customqueue")
19
+ assert_equal 1, Sidekiq.redis.llen("queue:customqueue")
20
20
  end
21
21
 
22
22
  it 'does push duplicate messages when not configured for unique only' do
23
- Sidekiq::Client.middleware.unregister(Sidekiq::Middleware::Client::UniqueJobs)
23
+ Sidekiq.client_middleware.remove(Sidekiq::Middleware::Client::UniqueJobs)
24
24
  10.times { Sidekiq::Client.push('customqueue2', 'class' => 'Foo', 'args' => [1, 2]) }
25
- assert_equal 10, Sidekiq::Client.redis.llen("queue:customqueue2")
25
+ assert_equal 10, Sidekiq.redis.llen("queue:customqueue2")
26
26
  end
27
27
  end
28
28
 
@@ -38,7 +38,8 @@ class TestClient < MiniTest::Unit::TestCase
38
38
  def @redis.incrby(*); nil; end
39
39
  def @redis.setex(*); nil; end
40
40
  def @redis.expire(*); true; end
41
- Sidekiq::Client.redis = @redis
41
+ def @redis.with_connection; yield self; end
42
+ Sidekiq.redis = @redis
42
43
  end
43
44
 
44
45
  it 'raises ArgumentError with invalid params' do
@@ -88,5 +89,15 @@ class TestClient < MiniTest::Unit::TestCase
88
89
  assert pushed
89
90
  @redis.verify
90
91
  end
92
+
93
+ it 'retrieves queues' do
94
+ @redis.expect :smembers, ['bob'], ['queues']
95
+ assert_equal ['bob'], Sidekiq::Client.registered_queues
96
+ end
97
+
98
+ it 'retrieves workers' do
99
+ @redis.expect :smembers, ['bob'], ['workers']
100
+ assert_equal ['bob'], Sidekiq::Client.registered_workers
101
+ end
91
102
  end
92
103
  end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+ require 'sidekiq'
3
+ require 'active_record'
4
+ require 'action_mailer'
5
+ require 'sidekiq/extensions/action_mailer'
6
+ require 'sidekiq/extensions/active_record'
7
+
8
+
9
+ class TestExtensions < MiniTest::Unit::TestCase
10
+ describe 'sidekiq extensions' do
11
+ before do
12
+ Sidekiq.client_middleware.entries.clear
13
+ Sidekiq.redis = @redis = MiniTest::Mock.new
14
+ end
15
+
16
+ class MyModel < ActiveRecord::Base
17
+ def self.long_class_method
18
+ raise "Should not be called!"
19
+ end
20
+ end
21
+
22
+ it 'allows delayed exection of ActiveRecord class methods' do
23
+ @redis.expect(:rpush, @redis, ['queue:default', "{\"class\":\"Sidekiq::Extensions::DelayedModel\",\"args\":[\"---\\n- !ruby/class 'TestExtensions::MyModel'\\n- :long_class_method\\n- []\\n\"]}"])
24
+ MyModel.delay.long_class_method
25
+ @redis.verify
26
+ end
27
+
28
+ it 'allows delayed exection of ActiveRecord instance methods' do
29
+ skip('requires a database')
30
+ end
31
+
32
+ class UserMailer < ActionMailer::Base
33
+ def greetings(a, b)
34
+ raise "Should not be called!"
35
+ end
36
+ end
37
+
38
+ it 'allows delayed delivery of ActionMailer mails' do
39
+ @redis.expect(:rpush, @redis, ['queue:default', "{\"class\":\"Sidekiq::Extensions::DelayedMailer\",\"args\":[\"---\\n- !ruby/class 'TestExtensions::UserMailer'\\n- :greetings\\n- - 1\\n - 2\\n\"]}"])
40
+ UserMailer.delay.greetings(1, 2)
41
+ @redis.verify
42
+ end
43
+
44
+ end
45
+ end
data/test/test_manager.rb CHANGED
@@ -8,7 +8,7 @@ require 'connection_pool'
8
8
  class TestManager < MiniTest::Unit::TestCase
9
9
  describe 'with redis' do
10
10
  before do
11
- Sidekiq::Manager.redis = Sidekiq::Client.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
11
+ Sidekiq.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
12
12
  @redis.flushdb
13
13
  $processed = 0
14
14
  $mutex = Mutex.new
@@ -30,7 +30,7 @@ class TestManager < MiniTest::Unit::TestCase
30
30
  Sidekiq::Client.push(:foo, 'class' => IntegrationWorker, 'args' => [1, 3])
31
31
 
32
32
  q = TimedQueue.new
33
- mgr = Sidekiq::Manager.new(:queues => [:foo], :processor_count => 2)
33
+ mgr = Sidekiq::Manager.new(:queues => [:foo], :concurrency => 2)
34
34
  mgr.when_done do |_|
35
35
  q << 'done' if $processed == 2
36
36
  end
@@ -6,8 +6,7 @@ require 'sidekiq/processor'
6
6
  class TestMiddleware < MiniTest::Unit::TestCase
7
7
  describe 'middleware chain' do
8
8
  before do
9
- Sidekiq::Manager.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
10
- Sidekiq::Client.redis = nil
9
+ Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
11
10
  end
12
11
 
13
12
  class CustomMiddleware
@@ -25,9 +24,7 @@ class TestMiddleware < MiniTest::Unit::TestCase
25
24
 
26
25
  it 'supports custom middleware' do
27
26
  chain = Sidekiq::Middleware::Chain.new
28
- chain.register do
29
- use CustomMiddleware, 1, []
30
- end
27
+ chain.add CustomMiddleware, 1, []
31
28
 
32
29
  assert_equal CustomMiddleware, chain.entries.last.klass
33
30
  end
@@ -52,8 +49,9 @@ class TestMiddleware < MiniTest::Unit::TestCase
52
49
  recorder = []
53
50
  msg = { 'class' => CustomWorker.to_s, 'args' => [recorder] }
54
51
 
55
- Sidekiq::Processor.middleware.register do
56
- 2.times { |i| use CustomMiddleware, i.to_s, recorder }
52
+ Sidekiq.server_middleware do |chain|
53
+ # should only add once, second should be ignored
54
+ 2.times { |i| chain.add CustomMiddleware, i.to_s, recorder }
57
55
  end
58
56
 
59
57
  boss = MiniTest::Mock.new
@@ -66,11 +64,8 @@ class TestMiddleware < MiniTest::Unit::TestCase
66
64
  it 'allows middleware to abruptly stop processing rest of chain' do
67
65
  recorder = []
68
66
  chain = Sidekiq::Middleware::Chain.new
69
-
70
- chain.register do
71
- use NonYieldingMiddleware
72
- use CustomMiddleware, 1, recorder
73
- end
67
+ chain.add NonYieldingMiddleware
68
+ chain.add CustomMiddleware, 1, recorder
74
69
 
75
70
  final_action = nil
76
71
  chain.invoke { final_action = true }
data/test/test_stats.rb CHANGED
@@ -5,8 +5,7 @@ require 'sidekiq/processor'
5
5
  class TestStats < MiniTest::Unit::TestCase
6
6
  describe 'with redis' do
7
7
  before do
8
- Sidekiq::Manager.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
9
- Sidekiq::Client.redis = nil
8
+ Sidekiq.redis = @redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/sidekiq_test')
10
9
  @redis.flushdb
11
10
  end
12
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-14 00:00:00.000000000 Z
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70220996079880 !ruby/object:Gem::Requirement
16
+ requirement: &70319633540020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70220996079880
24
+ version_requirements: *70319633540020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis-namespace
27
- requirement: &70220996078920 !ruby/object:Gem::Requirement
27
+ requirement: &70319633539280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70220996078920
35
+ version_requirements: *70319633539280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: connection_pool
38
- requirement: &70220996094360 !ruby/object:Gem::Requirement
38
+ requirement: &70319633537820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70220996094360
46
+ version_requirements: *70319633537820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: celluloid
49
- requirement: &70220996093580 !ruby/object:Gem::Requirement
49
+ requirement: &70319633533720 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70220996093580
57
+ version_requirements: *70319633533720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70220996093020 !ruby/object:Gem::Requirement
60
+ requirement: &70319633624400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70220996093020
68
+ version_requirements: *70319633624400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
- requirement: &70220996092320 !ruby/object:Gem::Requirement
71
+ requirement: &70319633623480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70220996092320
79
+ version_requirements: *70319633623480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &70220996091640 !ruby/object:Gem::Requirement
82
+ requirement: &70319633622760 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,29 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70220996091640
90
+ version_requirements: *70319633622760
91
+ - !ruby/object:Gem::Dependency
92
+ name: actionmailer
93
+ requirement: &70319633621420 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70319633621420
102
+ - !ruby/object:Gem::Dependency
103
+ name: activerecord
104
+ requirement: &70319633620680 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70319633620680
91
113
  description: Simple, efficient message processing for Ruby
92
114
  email:
93
115
  - mperham@gmail.com
@@ -98,6 +120,7 @@ extra_rdoc_files: []
98
120
  files:
99
121
  - .gitignore
100
122
  - .rvmrc
123
+ - .travis.yml
101
124
  - COMM-LICENSE
102
125
  - Changes.md
103
126
  - Gemfile
@@ -107,17 +130,27 @@ files:
107
130
  - TODO.md
108
131
  - bin/client
109
132
  - bin/sidekiq
133
+ - examples/chef/cookbooks/sidekiq/README.rdoc
134
+ - examples/chef/cookbooks/sidekiq/recipes/default.rb
135
+ - examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb
136
+ - examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb
137
+ - examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb
138
+ - examples/monitrc.conf
110
139
  - examples/por.rb
111
140
  - examples/sinkiq.rb
112
141
  - lib/sidekiq.rb
113
142
  - lib/sidekiq/cli.rb
114
143
  - lib/sidekiq/client.rb
144
+ - lib/sidekiq/extensions/action_mailer.rb
145
+ - lib/sidekiq/extensions/active_record.rb
146
+ - lib/sidekiq/extensions/generic_proxy.rb
115
147
  - lib/sidekiq/manager.rb
116
148
  - lib/sidekiq/middleware/chain.rb
117
149
  - lib/sidekiq/middleware/client/resque_web_compatibility.rb
118
150
  - lib/sidekiq/middleware/client/unique_jobs.rb
119
151
  - lib/sidekiq/middleware/server/active_record.rb
120
152
  - lib/sidekiq/middleware/server/airbrake.rb
153
+ - lib/sidekiq/middleware/server/failure_jobs.rb
121
154
  - lib/sidekiq/middleware/server/unique_jobs.rb
122
155
  - lib/sidekiq/processor.rb
123
156
  - lib/sidekiq/rails.rb
@@ -134,9 +167,11 @@ files:
134
167
  - myapp/app/controllers/work_controller.rb
135
168
  - myapp/app/helpers/application_helper.rb
136
169
  - myapp/app/mailers/.gitkeep
170
+ - myapp/app/mailers/user_mailer.rb
137
171
  - myapp/app/models/.gitkeep
138
172
  - myapp/app/models/post.rb
139
173
  - myapp/app/views/layouts/application.html.erb
174
+ - myapp/app/views/user_mailer/greetings.html.erb
140
175
  - myapp/app/views/work/index.html.erb
141
176
  - myapp/app/workers/hard_worker.rb
142
177
  - myapp/config.ru
@@ -163,10 +198,12 @@ files:
163
198
  - myapp/log/.gitkeep
164
199
  - myapp/script/rails
165
200
  - sidekiq.gemspec
201
+ - test/config.yml
166
202
  - test/fake_env.rb
167
203
  - test/helper.rb
168
204
  - test/test_cli.rb
169
205
  - test/test_client.rb
206
+ - test/test_extensions.rb
170
207
  - test/test_manager.rb
171
208
  - test/test_middleware.rb
172
209
  - test/test_processor.rb
@@ -197,10 +234,12 @@ signing_key:
197
234
  specification_version: 3
198
235
  summary: Simple, efficient message processing for Ruby
199
236
  test_files:
237
+ - test/config.yml
200
238
  - test/fake_env.rb
201
239
  - test/helper.rb
202
240
  - test/test_cli.rb
203
241
  - test/test_client.rb
242
+ - test/test_extensions.rb
204
243
  - test/test_manager.rb
205
244
  - test/test_middleware.rb
206
245
  - test/test_processor.rb