sidekiq 0.5.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.
- data/.rvmrc +3 -0
- data/COMM-LICENSE +75 -0
- data/Changes.md +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +9 -0
- data/README.md +64 -0
- data/Rakefile +8 -0
- data/TODO.md +4 -0
- data/bin/client +7 -0
- data/bin/sidekiq +19 -0
- data/lib/sidekiq.rb +4 -0
- data/lib/sidekiq/cli.rb +100 -0
- data/lib/sidekiq/client.rb +47 -0
- data/lib/sidekiq/manager.rb +131 -0
- data/lib/sidekiq/middleware.rb +89 -0
- data/lib/sidekiq/processor.rb +37 -0
- data/lib/sidekiq/rails.rb +5 -0
- data/lib/sidekiq/util.rb +36 -0
- data/lib/sidekiq/version.rb +3 -0
- data/lib/sidekiq/worker.rb +42 -0
- data/myapp/.gitignore +15 -0
- data/myapp/Gemfile +5 -0
- data/myapp/Gemfile.lock +100 -0
- data/myapp/Rakefile +7 -0
- data/myapp/app/controllers/application_controller.rb +3 -0
- data/myapp/app/helpers/application_helper.rb +2 -0
- data/myapp/app/mailers/.gitkeep +0 -0
- data/myapp/app/models/.gitkeep +0 -0
- data/myapp/app/models/post.rb +2 -0
- data/myapp/app/views/layouts/application.html.erb +14 -0
- data/myapp/app/workers/hard_worker.rb +6 -0
- data/myapp/config.ru +4 -0
- data/myapp/config/application.rb +59 -0
- data/myapp/config/boot.rb +6 -0
- data/myapp/config/database.yml +25 -0
- data/myapp/config/environment.rb +5 -0
- data/myapp/config/environments/development.rb +37 -0
- data/myapp/config/environments/production.rb +67 -0
- data/myapp/config/environments/test.rb +37 -0
- data/myapp/config/initializers/backtrace_silencers.rb +7 -0
- data/myapp/config/initializers/inflections.rb +15 -0
- data/myapp/config/initializers/mime_types.rb +5 -0
- data/myapp/config/initializers/secret_token.rb +7 -0
- data/myapp/config/initializers/session_store.rb +8 -0
- data/myapp/config/initializers/wrap_parameters.rb +14 -0
- data/myapp/config/locales/en.yml +5 -0
- data/myapp/config/routes.rb +58 -0
- data/myapp/db/migrate/20120123214055_create_posts.rb +10 -0
- data/myapp/db/seeds.rb +7 -0
- data/myapp/lib/assets/.gitkeep +0 -0
- data/myapp/lib/tasks/.gitkeep +0 -0
- data/myapp/log/.gitkeep +0 -0
- data/myapp/script/rails +6 -0
- data/sidekiq.gemspec +22 -0
- data/test/helper.rb +9 -0
- data/test/test_client.rb +50 -0
- data/test/test_manager.rb +38 -0
- data/test/test_middleware.rb +62 -0
- data/test/test_processor.rb +52 -0
- data/test/timed_queue.rb +42 -0
- metadata +179 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq/middleware'
|
3
|
+
require 'sidekiq/processor'
|
4
|
+
|
5
|
+
class TestMiddleware < MiniTest::Unit::TestCase
|
6
|
+
describe 'middleware chain' do
|
7
|
+
before do
|
8
|
+
@boss = MiniTest::Mock.new
|
9
|
+
Celluloid.logger = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
class CustomMiddleware
|
13
|
+
def initialize(name, recorder)
|
14
|
+
@name = name
|
15
|
+
@recorder = recorder
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(worker, msg)
|
19
|
+
@recorder << [@name, 'before']
|
20
|
+
yield
|
21
|
+
@recorder << [@name, 'after']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'configures default middleware' do
|
26
|
+
chain = Sidekiq::Middleware::Chain.chain
|
27
|
+
assert_equal chain, Sidekiq::Middleware::Chain.default
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'supports custom middleware' do
|
31
|
+
Sidekiq::Middleware::Chain.register do
|
32
|
+
use CustomMiddleware, 1, []
|
33
|
+
end
|
34
|
+
chain = Sidekiq::Middleware::Chain.chain
|
35
|
+
assert_equal chain.last.klass, CustomMiddleware
|
36
|
+
end
|
37
|
+
|
38
|
+
class CustomWorker
|
39
|
+
def perform(recorder)
|
40
|
+
recorder << ['work_performed']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'executes middleware in the proper order' do
|
45
|
+
recorder = []
|
46
|
+
msg = { 'class' => CustomWorker.to_s, 'args' => [recorder] }
|
47
|
+
|
48
|
+
Sidekiq::Middleware::Chain.register do
|
49
|
+
2.times { |i| use CustomMiddleware, i.to_s, recorder }
|
50
|
+
end
|
51
|
+
|
52
|
+
processor = Sidekiq::Processor.new(@boss)
|
53
|
+
@boss.expect(:processor_done!, nil, [processor])
|
54
|
+
processor.process(msg)
|
55
|
+
assert_equal recorder.flatten, %w(0 before 1 before work_performed 1 after 0 after)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq/processor'
|
3
|
+
|
4
|
+
class TestProcessor < MiniTest::Unit::TestCase
|
5
|
+
describe 'with mock setup' do
|
6
|
+
before do
|
7
|
+
$invokes = 0
|
8
|
+
$errors = []
|
9
|
+
@boss = MiniTest::Mock.new
|
10
|
+
Celluloid.logger = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
class MockWorker
|
14
|
+
def perform(args)
|
15
|
+
raise "kerboom!" if args == 'boom'
|
16
|
+
$invokes += 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'processes as expected' do
|
21
|
+
msg = { 'class' => MockWorker.to_s, 'args' => ['myarg'] }
|
22
|
+
processor = ::Sidekiq::Processor.new(@boss)
|
23
|
+
@boss.expect(:processor_done!, nil, [processor])
|
24
|
+
processor.process(msg)
|
25
|
+
@boss.verify
|
26
|
+
assert_equal 1, $invokes
|
27
|
+
assert_equal 0, $errors.size
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'handles exceptions' do
|
31
|
+
msg = { 'class' => MockWorker.to_s, 'args' => ['boom'] }
|
32
|
+
processor = ::Sidekiq::Processor.new(@boss)
|
33
|
+
assert_raises RuntimeError do
|
34
|
+
processor.process(msg)
|
35
|
+
end
|
36
|
+
@boss.verify
|
37
|
+
assert_equal 0, $invokes
|
38
|
+
assert_equal 1, $errors.size
|
39
|
+
assert_equal "RuntimeError", $errors[0][:error_class]
|
40
|
+
assert_equal msg, $errors[0][:parameters]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class FakeAirbrake
|
47
|
+
def self.notify(hash)
|
48
|
+
$errors << hash
|
49
|
+
end
|
50
|
+
end
|
51
|
+
Airbrake = FakeAirbrake
|
52
|
+
|
data/test/timed_queue.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'thread'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
class TimedQueue
|
5
|
+
def initialize
|
6
|
+
@que = []
|
7
|
+
@mutex = Mutex.new
|
8
|
+
@resource = ConditionVariable.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def push(obj)
|
12
|
+
@mutex.synchronize do
|
13
|
+
@que.push obj
|
14
|
+
@resource.broadcast
|
15
|
+
end
|
16
|
+
end
|
17
|
+
alias_method :<<, :push
|
18
|
+
|
19
|
+
def timed_pop(timeout=0.5)
|
20
|
+
deadline = Time.now + timeout
|
21
|
+
@mutex.synchronize do
|
22
|
+
loop do
|
23
|
+
return @que.shift unless @que.empty?
|
24
|
+
to_wait = deadline - Time.now
|
25
|
+
raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0
|
26
|
+
@resource.wait(@mutex, to_wait)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def empty?
|
32
|
+
@que.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def clear
|
36
|
+
@que.clear
|
37
|
+
end
|
38
|
+
|
39
|
+
def length
|
40
|
+
@que.length
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Perham
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &70202868236280 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70202868236280
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: connection_pool
|
27
|
+
requirement: &70202868235720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70202868235720
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: celluloid
|
38
|
+
requirement: &70202868235160 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70202868235160
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: multi_json
|
49
|
+
requirement: &70202868234620 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70202868234620
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: minitest
|
60
|
+
requirement: &70202868234100 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70202868234100
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &70202868233600 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70202868233600
|
80
|
+
description: Simple, efficient message processing for Ruby
|
81
|
+
email:
|
82
|
+
- mperham@gmail.com
|
83
|
+
executables:
|
84
|
+
- sidekiq
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .rvmrc
|
89
|
+
- COMM-LICENSE
|
90
|
+
- Changes.md
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- TODO.md
|
97
|
+
- bin/client
|
98
|
+
- bin/sidekiq
|
99
|
+
- lib/sidekiq.rb
|
100
|
+
- lib/sidekiq/cli.rb
|
101
|
+
- lib/sidekiq/client.rb
|
102
|
+
- lib/sidekiq/manager.rb
|
103
|
+
- lib/sidekiq/middleware.rb
|
104
|
+
- lib/sidekiq/processor.rb
|
105
|
+
- lib/sidekiq/rails.rb
|
106
|
+
- lib/sidekiq/util.rb
|
107
|
+
- lib/sidekiq/version.rb
|
108
|
+
- lib/sidekiq/worker.rb
|
109
|
+
- myapp/.gitignore
|
110
|
+
- myapp/Gemfile
|
111
|
+
- myapp/Gemfile.lock
|
112
|
+
- myapp/Rakefile
|
113
|
+
- myapp/app/controllers/application_controller.rb
|
114
|
+
- myapp/app/helpers/application_helper.rb
|
115
|
+
- myapp/app/mailers/.gitkeep
|
116
|
+
- myapp/app/models/.gitkeep
|
117
|
+
- myapp/app/models/post.rb
|
118
|
+
- myapp/app/views/layouts/application.html.erb
|
119
|
+
- myapp/app/workers/hard_worker.rb
|
120
|
+
- myapp/config.ru
|
121
|
+
- myapp/config/application.rb
|
122
|
+
- myapp/config/boot.rb
|
123
|
+
- myapp/config/database.yml
|
124
|
+
- myapp/config/environment.rb
|
125
|
+
- myapp/config/environments/development.rb
|
126
|
+
- myapp/config/environments/production.rb
|
127
|
+
- myapp/config/environments/test.rb
|
128
|
+
- myapp/config/initializers/backtrace_silencers.rb
|
129
|
+
- myapp/config/initializers/inflections.rb
|
130
|
+
- myapp/config/initializers/mime_types.rb
|
131
|
+
- myapp/config/initializers/secret_token.rb
|
132
|
+
- myapp/config/initializers/session_store.rb
|
133
|
+
- myapp/config/initializers/wrap_parameters.rb
|
134
|
+
- myapp/config/locales/en.yml
|
135
|
+
- myapp/config/routes.rb
|
136
|
+
- myapp/db/migrate/20120123214055_create_posts.rb
|
137
|
+
- myapp/db/seeds.rb
|
138
|
+
- myapp/lib/assets/.gitkeep
|
139
|
+
- myapp/lib/tasks/.gitkeep
|
140
|
+
- myapp/log/.gitkeep
|
141
|
+
- myapp/script/rails
|
142
|
+
- sidekiq.gemspec
|
143
|
+
- test/helper.rb
|
144
|
+
- test/test_client.rb
|
145
|
+
- test/test_manager.rb
|
146
|
+
- test/test_middleware.rb
|
147
|
+
- test/test_processor.rb
|
148
|
+
- test/timed_queue.rb
|
149
|
+
homepage: http://mperham.github.com/sidekiq
|
150
|
+
licenses: []
|
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
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 1.8.15
|
170
|
+
signing_key:
|
171
|
+
specification_version: 3
|
172
|
+
summary: Simple, efficient message processing for Ruby
|
173
|
+
test_files:
|
174
|
+
- test/helper.rb
|
175
|
+
- test/test_client.rb
|
176
|
+
- test/test_manager.rb
|
177
|
+
- test/test_middleware.rb
|
178
|
+
- test/test_processor.rb
|
179
|
+
- test/timed_queue.rb
|