backburner 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -4
- data/HOOKS.md +23 -14
- data/README.md +102 -23
- data/bin/backburner +1 -1
- data/lib/active_job/queue_adapters/backburner_adapter.rb +19 -5
- data/lib/backburner/cli.rb +1 -1
- data/lib/backburner/configuration.rb +7 -0
- data/lib/backburner/connection.rb +4 -2
- data/lib/backburner/enqueue_pool.rb +90 -0
- data/lib/backburner/helpers.rb +77 -22
- data/lib/backburner/job.rb +46 -7
- data/lib/backburner/logger.rb +9 -0
- data/lib/backburner/performable.rb +29 -4
- data/lib/backburner/queue.rb +37 -19
- data/lib/backburner/version.rb +1 -1
- data/lib/backburner/worker.rb +150 -25
- data/lib/backburner/workers/forking.rb +4 -2
- data/lib/backburner/workers/simple.rb +5 -0
- data/lib/backburner/workers/threading.rb +17 -7
- data/lib/backburner/workers/threads_on_fork.rb +59 -23
- data/lib/backburner.rb +7 -1
- metadata +40 -66
- data/.gitignore +0 -17
- data/.travis.yml +0 -29
- data/CONTRIBUTING.md +0 -37
- data/Gemfile +0 -4
- data/Rakefile +0 -17
- data/TODO +0 -4
- data/backburner.gemspec +0 -28
- data/circle.yml +0 -3
- data/examples/custom.rb +0 -25
- data/examples/demo.rb +0 -60
- data/examples/god.rb +0 -46
- data/examples/hooked.rb +0 -87
- data/examples/retried.rb +0 -31
- data/examples/simple.rb +0 -43
- data/examples/stress.rb +0 -31
- data/test/async_proxy_test.rb +0 -36
- data/test/back_burner_test.rb +0 -88
- data/test/connection_test.rb +0 -179
- data/test/fixtures/active_jobs.rb +0 -11
- data/test/fixtures/hooked.rb +0 -122
- data/test/fixtures/test_fork_jobs.rb +0 -72
- data/test/fixtures/test_forking_jobs.rb +0 -56
- data/test/fixtures/test_jobs.rb +0 -87
- data/test/fixtures/test_queue_settings.rb +0 -14
- data/test/helpers/templogger.rb +0 -22
- data/test/helpers_test.rb +0 -278
- data/test/hooks_test.rb +0 -112
- data/test/job_test.rb +0 -185
- data/test/logger_test.rb +0 -44
- data/test/performable_test.rb +0 -88
- data/test/queue_test.rb +0 -69
- data/test/test_helper.rb +0 -125
- data/test/worker_test.rb +0 -157
- data/test/workers/forking_worker_test.rb +0 -181
- data/test/workers/simple_worker_test.rb +0 -350
- data/test/workers/threading_worker_test.rb +0 -104
- data/test/workers/threads_on_fork_worker_test.rb +0 -484
data/test/helpers_test.rb
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe "Backburner::Helpers module" do
|
|
4
|
-
include Backburner::Helpers
|
|
5
|
-
|
|
6
|
-
describe "for classify method" do
|
|
7
|
-
it "should support simple classify" do
|
|
8
|
-
assert_equal "FooBarBaz", classify("foo-bar-baz")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should not affect existing classified strings" do
|
|
12
|
-
assert_equal "Foo::BarBaz", classify("Foo::BarBaz")
|
|
13
|
-
end
|
|
14
|
-
end # classify
|
|
15
|
-
|
|
16
|
-
describe "for constantize method" do
|
|
17
|
-
it "should constantize known constant" do
|
|
18
|
-
assert_equal Backburner, constantize("Backburner")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "should properly report when constant is undefined" do
|
|
22
|
-
assert_raises(NameError) { constantize("FakeObject") }
|
|
23
|
-
end
|
|
24
|
-
end # constantize
|
|
25
|
-
|
|
26
|
-
describe "for dasherize method" do
|
|
27
|
-
it "should not harm existing dashed names" do
|
|
28
|
-
assert_equal "foo/bar-baz", dasherize("foo/bar-baz")
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "should properly convert simple names to dashes" do
|
|
32
|
-
assert_equal "foo-bar", dasherize("FooBar")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should properly convert class to dash with namespace" do
|
|
36
|
-
assert_equal "foo/bar-baz", dasherize("Foo::BarBaz")
|
|
37
|
-
end
|
|
38
|
-
end # dasherize
|
|
39
|
-
|
|
40
|
-
describe "for exception_message method" do
|
|
41
|
-
it "prints out message about failure" do
|
|
42
|
-
output = exception_message(RuntimeError.new("test"))
|
|
43
|
-
assert_match(/Exception RuntimeError/, output)
|
|
44
|
-
end
|
|
45
|
-
end # exception_message
|
|
46
|
-
|
|
47
|
-
describe "for queue_config" do
|
|
48
|
-
before { Backburner.expects(:configuration).returns(stub(:tube_namespace => "test.foo.job", :namespace_separator => '.')) }
|
|
49
|
-
|
|
50
|
-
it "accesses correct value for namespace" do
|
|
51
|
-
assert_equal "test.foo.job", queue_config.tube_namespace
|
|
52
|
-
end
|
|
53
|
-
end # config
|
|
54
|
-
|
|
55
|
-
describe "for expand_tube_name method" do
|
|
56
|
-
before { Backburner.stubs(:configuration).returns(stub(:tube_namespace => "test.foo.job.", :namespace_separator => '.', :primary_queue => "backburner-jobs")) }
|
|
57
|
-
|
|
58
|
-
it "supports base strings" do
|
|
59
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name("email/send_news")
|
|
60
|
-
end # simple string
|
|
61
|
-
|
|
62
|
-
it "supports qualified strings" do
|
|
63
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name("test.foo.job.email/send_news")
|
|
64
|
-
end # qualified string
|
|
65
|
-
|
|
66
|
-
it "supports base symbols" do
|
|
67
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name(:"email/send_news")
|
|
68
|
-
end # symbols
|
|
69
|
-
|
|
70
|
-
it "supports queue names" do
|
|
71
|
-
test = stub(:queue => "email/send_news")
|
|
72
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name(test)
|
|
73
|
-
end # queue names
|
|
74
|
-
|
|
75
|
-
it "supports class names" do
|
|
76
|
-
assert_equal "test.foo.job.backburner-jobs", expand_tube_name(RuntimeError)
|
|
77
|
-
end # class names
|
|
78
|
-
|
|
79
|
-
it "supports lambda in queue object" do
|
|
80
|
-
test = stub(:queue => lambda { |job_class| "email/send_news" })
|
|
81
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name(test)
|
|
82
|
-
end # lambdas in queue object
|
|
83
|
-
|
|
84
|
-
it "supports lambdas" do
|
|
85
|
-
test = lambda { "email/send_news" }
|
|
86
|
-
assert_equal "test.foo.job.email/send-news", expand_tube_name(test)
|
|
87
|
-
end #lambdas
|
|
88
|
-
end # expand_tube_name
|
|
89
|
-
|
|
90
|
-
describe "for alternative namespace separator" do
|
|
91
|
-
before { Backburner.stubs(:configuration).returns(stub(:tube_namespace => "test", :namespace_separator => '-', :primary_queue => "backburner-jobs")) }
|
|
92
|
-
|
|
93
|
-
it "uses alternative namespace separator" do
|
|
94
|
-
assert_equal "test-queue-name", expand_tube_name("queue_name")
|
|
95
|
-
end # simple string
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
describe "for resolve_priority method" do
|
|
99
|
-
before do
|
|
100
|
-
@original_queue_priority = Backburner.configuration.default_priority
|
|
101
|
-
Backburner.configure { |config| config.default_priority = 1000 }
|
|
102
|
-
end
|
|
103
|
-
after do
|
|
104
|
-
Backburner.configure { |config| config.default_priority = @original_queue_priority }
|
|
105
|
-
Backburner.configure { |config| config.priority_labels = Backburner::Configuration::PRIORITY_LABELS }
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "supports fix num priority" do
|
|
109
|
-
assert_equal 500, resolve_priority(500)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "supports baked in priority alias" do
|
|
113
|
-
assert_equal 200, resolve_priority(:low)
|
|
114
|
-
assert_equal 0, resolve_priority(:high)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "supports custom priority alias" do
|
|
118
|
-
Backburner.configure { |config| config.priority_labels = { :foo => 5 } }
|
|
119
|
-
assert_equal 5, resolve_priority(:foo)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "supports aliased priority alias" do
|
|
123
|
-
Backburner.configure { |config| config.priority_labels = { :foo => 5, :bar => 'foo' } }
|
|
124
|
-
assert_equal 5, resolve_priority(:bar)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it "supports classes which respond to queue_priority" do
|
|
128
|
-
job = stub(:queue_priority => 600)
|
|
129
|
-
assert_equal 600, resolve_priority(job)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "supports classes which respond to queue_priority with named alias" do
|
|
133
|
-
job = stub(:queue_priority => :low)
|
|
134
|
-
assert_equal 200, resolve_priority(job)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "supports classes which returns null queue_priority" do
|
|
138
|
-
job = stub(:queue_priority => nil)
|
|
139
|
-
assert_equal 1000, resolve_priority(job)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
it "supports classes which don't respond to queue_priority" do
|
|
143
|
-
job = stub(:fake => true)
|
|
144
|
-
assert_equal 1000, resolve_priority(job)
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "supports default pri for null values" do
|
|
148
|
-
assert_equal 1000, resolve_priority(nil)
|
|
149
|
-
end
|
|
150
|
-
end # resolve_priority
|
|
151
|
-
|
|
152
|
-
describe "for resolve_respond_timeout method" do
|
|
153
|
-
before do
|
|
154
|
-
@original_respond_timeout = Backburner.configuration.respond_timeout
|
|
155
|
-
Backburner.configure { |config| config.respond_timeout = 300 }
|
|
156
|
-
end
|
|
157
|
-
after { Backburner.configure { |config| config.respond_timeout = @original_respond_timeout } }
|
|
158
|
-
|
|
159
|
-
it "supports fix num respond_timeout" do
|
|
160
|
-
assert_equal 500, resolve_respond_timeout(500)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "supports classes which respond to queue_respond_timeout" do
|
|
164
|
-
job = stub(:queue_respond_timeout => 600)
|
|
165
|
-
assert_equal 600, resolve_respond_timeout(job)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it "supports classes which returns null queue_respond_timeout" do
|
|
169
|
-
job = stub(:queue_respond_timeout => nil)
|
|
170
|
-
assert_equal 300, resolve_respond_timeout(job)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it "supports classes which don't respond to queue_respond_timeout" do
|
|
174
|
-
job = stub(:fake => true)
|
|
175
|
-
assert_equal 300, resolve_respond_timeout(job)
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it "supports default ttr for null values" do
|
|
179
|
-
assert_equal 300, resolve_respond_timeout(nil)
|
|
180
|
-
end
|
|
181
|
-
end # resolve_respond_timeout
|
|
182
|
-
|
|
183
|
-
describe "for resolve_max_job_retries method" do
|
|
184
|
-
before do
|
|
185
|
-
@original_max_job_retries = Backburner.configuration.max_job_retries
|
|
186
|
-
Backburner.configure { |config| config.max_job_retries = 300 }
|
|
187
|
-
end
|
|
188
|
-
after { Backburner.configure { |config| config.max_job_retries = @original_max_job_retries } }
|
|
189
|
-
|
|
190
|
-
it "supports fix num max_job_retries" do
|
|
191
|
-
assert_equal 500, resolve_max_job_retries(500)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
it "supports classes which respond to queue_max_job_retries" do
|
|
195
|
-
job = stub(:queue_max_job_retries => 600)
|
|
196
|
-
assert_equal 600, resolve_max_job_retries(job)
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
it "supports classes which return null queue_max_job_retries" do
|
|
200
|
-
job = stub(:queue_max_job_retries => nil)
|
|
201
|
-
assert_equal 300, resolve_max_job_retries(job)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "supports classes which don't respond to queue_max_job_retries" do
|
|
205
|
-
job = stub(:fake => true)
|
|
206
|
-
assert_equal 300, resolve_max_job_retries(job)
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
it "supports default max_job_retries for null values" do
|
|
210
|
-
assert_equal 300, resolve_max_job_retries(nil)
|
|
211
|
-
end
|
|
212
|
-
end # resolve_max_job_retries
|
|
213
|
-
|
|
214
|
-
describe "for resolve_retry_delay method" do
|
|
215
|
-
before do
|
|
216
|
-
@original_retry_delay = Backburner.configuration.retry_delay
|
|
217
|
-
Backburner.configure { |config| config.retry_delay = 300 }
|
|
218
|
-
end
|
|
219
|
-
after { Backburner.configure { |config| config.retry_delay = @original_retry_delay } }
|
|
220
|
-
|
|
221
|
-
it "supports fix num retry_delay" do
|
|
222
|
-
assert_equal 500, resolve_retry_delay(500)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
it "supports classes which respond to queue_retry_delay" do
|
|
226
|
-
job = stub(:queue_retry_delay => 600)
|
|
227
|
-
assert_equal 600, resolve_retry_delay(job)
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
it "supports classes which return null queue_retry_delay" do
|
|
231
|
-
job = stub(:queue_retry_delay => nil)
|
|
232
|
-
assert_equal 300, resolve_retry_delay(job)
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it "supports classes which don't respond to queue_retry_delay" do
|
|
236
|
-
job = stub(:fake => true)
|
|
237
|
-
assert_equal 300, resolve_retry_delay(job)
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
it "supports default retry_delay for null values" do
|
|
241
|
-
assert_equal 300, resolve_retry_delay(nil)
|
|
242
|
-
end
|
|
243
|
-
end # resolve_retry_delay
|
|
244
|
-
|
|
245
|
-
describe "for resolve_retry_delay_proc method" do
|
|
246
|
-
before do
|
|
247
|
-
@config_retry_delay_proc = lambda { |x, y| x + y } # Default config proc adds two values
|
|
248
|
-
@override_delay_proc = lambda { |x, y| x - y } # Overriden proc subtracts values
|
|
249
|
-
@original_retry_delay_proc = Backburner.configuration.retry_delay_proc
|
|
250
|
-
Backburner.configure { |config| config.retry_delay_proc = @config_retry_delay_proc }
|
|
251
|
-
end
|
|
252
|
-
after { Backburner.configure { |config| config.retry_delay_proc = @original_retry_delay_proc } }
|
|
253
|
-
|
|
254
|
-
# Rather than compare Procs execute them and compare the output
|
|
255
|
-
it "supports proc retry_delay_proc" do
|
|
256
|
-
assert_equal @override_delay_proc.call(2, 1), resolve_retry_delay_proc(@override_delay_proc).call(2, 1)
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it "supports classes which respond to queue_retry_delay_proc" do
|
|
260
|
-
job = stub(:queue_retry_delay_proc => @override_delay_proc)
|
|
261
|
-
assert_equal @override_delay_proc.call(2, 1), resolve_retry_delay_proc(job).call(2, 1)
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
it "supports classes which return null queue_retry_delay_proc" do
|
|
265
|
-
job = stub(:queue_retry_delay_proc => nil)
|
|
266
|
-
assert_equal @original_retry_delay_proc.call(2, 1), resolve_retry_delay_proc(job).call(2, 1)
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
it "supports classes which don't respond to queue_retry_delay_proc" do
|
|
270
|
-
job = stub(:fake => true)
|
|
271
|
-
assert_equal @original_retry_delay_proc.call(2, 1), resolve_retry_delay_proc(job).call(2, 1)
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it "supports default retry_delay_proc for null values" do
|
|
275
|
-
assert_equal @original_retry_delay_proc.call(2, 1), resolve_retry_delay_proc(nil).call(2, 1)
|
|
276
|
-
end
|
|
277
|
-
end # resolve_retry_delay_proc
|
|
278
|
-
end
|
data/test/hooks_test.rb
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
require File.expand_path('../fixtures/hooked', __FILE__)
|
|
3
|
-
|
|
4
|
-
describe "Backburner::Hooks module" do
|
|
5
|
-
before do
|
|
6
|
-
$hooked_fail_count = 0
|
|
7
|
-
@hooks = Backburner::Hooks
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe "for invoke_hook_events method" do
|
|
11
|
-
describe "with before_enqueue" do
|
|
12
|
-
it "should support successful invocation" do
|
|
13
|
-
out = silenced { @res = @hooks.invoke_hook_events(HookedObjectSuccess, :before_enqueue, 5, 6) }
|
|
14
|
-
assert_equal [nil, nil], @res
|
|
15
|
-
assert_match(/!!before_enqueue_foo!! \[5\, 6\]/, out)
|
|
16
|
-
assert_match(/!!before_enqueue_bar!! \[5\, 6\]/, out)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should support fail case" do
|
|
20
|
-
out = silenced { @res = @hooks.invoke_hook_events(HookedObjectBeforeEnqueueFail, :before_enqueue, 5, 6) }
|
|
21
|
-
assert_equal false, @res
|
|
22
|
-
assert_match(/!!before_enqueue_foo!! \[5\, 6\]/, out)
|
|
23
|
-
end
|
|
24
|
-
end # before_enqueue
|
|
25
|
-
|
|
26
|
-
describe "with after_enqueue" do
|
|
27
|
-
it "should support successful invocation" do
|
|
28
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :after_enqueue, 7, 8) }
|
|
29
|
-
assert_match(/!!after_enqueue_foo!! \[7\, 8\]/, out)
|
|
30
|
-
assert_match(/!!after_enqueue_bar!! \[7\, 8\]/, out)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should support fail case" do
|
|
34
|
-
assert_raises(HookFailError) do
|
|
35
|
-
silenced { @res = @hooks.invoke_hook_events(HookedObjectAfterEnqueueFail, :after_enqueue, 5, 6) }
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end # after_enqueue
|
|
39
|
-
|
|
40
|
-
describe "with before_perform" do
|
|
41
|
-
it "should support successful invocation" do
|
|
42
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :before_perform, 1, 2) }
|
|
43
|
-
assert_match(/!!before_perform_foo!! \[1\, 2\]/, out)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "should support fail case" do
|
|
47
|
-
out = silenced { @res = @hooks.invoke_hook_events(HookedObjectBeforePerformFail, :before_perform, 5, 6) }
|
|
48
|
-
assert_equal false, @res
|
|
49
|
-
assert_match(/!!before_perform_foo!! \[5\, 6\]/, out)
|
|
50
|
-
end
|
|
51
|
-
end # before_perform
|
|
52
|
-
|
|
53
|
-
describe "with after_perform" do
|
|
54
|
-
it "should support successful invocation" do
|
|
55
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :after_perform, 3, 4) }
|
|
56
|
-
assert_match(/!!after_perform_foo!! \[3\, 4\]/, out)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "should support fail case" do
|
|
60
|
-
assert_raises(HookFailError) do
|
|
61
|
-
silenced { @res = @hooks.invoke_hook_events(HookedObjectAfterPerformFail, :after_perform, 5, 6) }
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end # after_perform
|
|
65
|
-
|
|
66
|
-
describe "with on_failure" do
|
|
67
|
-
it "should support successful invocation" do
|
|
68
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :on_failure, RuntimeError, 10) }
|
|
69
|
-
assert_match(/!!on_failure_foo!! RuntimeError \[10\]/, out)
|
|
70
|
-
end
|
|
71
|
-
end # on_failure
|
|
72
|
-
|
|
73
|
-
describe 'with on_retry' do
|
|
74
|
-
it "should support successful invocation" do
|
|
75
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :on_retry, 1, 0, 10) }
|
|
76
|
-
assert_match(/!!on_retry_foo!! 1 0 \[10\]/, out)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe 'with on_bury' do
|
|
81
|
-
it "should support successful invocation" do
|
|
82
|
-
out = silenced { @hooks.invoke_hook_events(HookedObjectSuccess, :on_bury, 10) }
|
|
83
|
-
assert_match(/!!on_bury_foo!! \[10\]/, out)
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
describe "with on_reconnect" do
|
|
88
|
-
it "should support successful invocation" do
|
|
89
|
-
out = silenced { @hooks.invoke_hook_events(HookedWorker.new, :on_reconnect)}
|
|
90
|
-
assert_match(/!!on_reconnect!!/, out)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end # invoke_hook_events
|
|
94
|
-
|
|
95
|
-
describe "for around_hook_events method" do
|
|
96
|
-
describe "with around_perform" do
|
|
97
|
-
it "should support successful invocation" do
|
|
98
|
-
out = silenced do
|
|
99
|
-
@hooks.around_hook_events(HookedObjectSuccess, :around_perform, 7, 8) {
|
|
100
|
-
puts "!!FIRED!!"
|
|
101
|
-
}
|
|
102
|
-
end
|
|
103
|
-
assert_match(/BEGIN.*?bar.*BEGIN.*cat.*FIRED.*END.*cat.*END.*bar/m, out)
|
|
104
|
-
assert_match(/!!BEGIN around_perform_bar!! \[7\, 8\]/, out)
|
|
105
|
-
assert_match(/!!BEGIN around_perform_cat!! \[7\, 8\]/, out)
|
|
106
|
-
assert_match(/!!FIRED!!/, out)
|
|
107
|
-
assert_match(/!!END around_perform_cat!! \[7\, 8\]/, out)
|
|
108
|
-
assert_match(/!!END around_perform_bar!! \[7\, 8\]/, out)
|
|
109
|
-
end
|
|
110
|
-
end # successful
|
|
111
|
-
end # around_hook_events
|
|
112
|
-
end # Hooks
|
data/test/job_test.rb
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
module NestedDemo
|
|
4
|
-
class TestJobC
|
|
5
|
-
def self.perform(x); puts "Performed #{x} in #{self}"; end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
class TestJobD
|
|
9
|
-
include Backburner::Queue
|
|
10
|
-
def self.perform(x); raise RuntimeError; end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "Backburner::Job module" do
|
|
15
|
-
describe "for initialize" do
|
|
16
|
-
describe "with hash" do
|
|
17
|
-
before do
|
|
18
|
-
@task = stub(:body => task_body, :ttr => 120, :delete => true, :bury => true)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "with string keys" do
|
|
22
|
-
let(:task_body) { { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] } }
|
|
23
|
-
it "should create job with correct task data" do
|
|
24
|
-
@job = Backburner::Job.new(@task)
|
|
25
|
-
assert_equal @task, @job.task
|
|
26
|
-
assert_equal ["class", "args"], @job.body.keys
|
|
27
|
-
assert_equal task_body["class"], @job.name
|
|
28
|
-
assert_equal task_body["args"], @job.args
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "with symbol keys" do
|
|
33
|
-
let(:task_body) { { :class => "NewsletterSender", :args => ["foo@bar.com", "bar@foo.com"] } }
|
|
34
|
-
it "should create job with correct task data" do
|
|
35
|
-
@job = Backburner::Job.new(@task)
|
|
36
|
-
assert_equal @task, @job.task
|
|
37
|
-
assert_equal [:class, :args], @job.body.keys
|
|
38
|
-
assert_equal task_body[:class], @job.name
|
|
39
|
-
assert_equal task_body[:args], @job.args
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end # with hash
|
|
43
|
-
|
|
44
|
-
describe "with json string" do
|
|
45
|
-
before do
|
|
46
|
-
@task_body = { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] }
|
|
47
|
-
@task = stub(:body => @task_body.to_json, :ttr => 120, :delete => true, :bury => true)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should create job with correct task data" do
|
|
51
|
-
@job = Backburner::Job.new(@task)
|
|
52
|
-
assert_equal @task, @job.task
|
|
53
|
-
assert_equal ["class", "args"], @job.body.keys
|
|
54
|
-
assert_equal @task_body["class"], @job.name
|
|
55
|
-
assert_equal @task_body["args"], @job.args
|
|
56
|
-
end
|
|
57
|
-
end # with json
|
|
58
|
-
|
|
59
|
-
describe "with invalid string" do
|
|
60
|
-
before do
|
|
61
|
-
@task_body = "^%$*&^*"
|
|
62
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should raise a job format exception" do
|
|
66
|
-
assert_raises(Backburner::Job::JobFormatInvalid) {
|
|
67
|
-
@job = Backburner::Job.new(@task)
|
|
68
|
-
}
|
|
69
|
-
end
|
|
70
|
-
end # invalid
|
|
71
|
-
end # initialize
|
|
72
|
-
|
|
73
|
-
describe "for process method" do
|
|
74
|
-
describe "with valid task" do
|
|
75
|
-
before do
|
|
76
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
77
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
78
|
-
@task.expects(:delete).once
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should process task" do
|
|
82
|
-
@job = Backburner::Job.new(@task)
|
|
83
|
-
out = silenced(1) { @job.process }
|
|
84
|
-
assert_match(/Performed 56 in NestedDemo::TestJobC/, out)
|
|
85
|
-
end # process
|
|
86
|
-
end # valid
|
|
87
|
-
|
|
88
|
-
describe "with invalid task" do
|
|
89
|
-
before do
|
|
90
|
-
@task_body = { "class" => "NestedDemo::TestJobD", "args" => [56] }
|
|
91
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
92
|
-
@task.expects(:delete).never
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "should raise an exception" do
|
|
96
|
-
@job = Backburner::Job.new(@task)
|
|
97
|
-
assert_raises(RuntimeError) { @job.process }
|
|
98
|
-
end # error invalid
|
|
99
|
-
end # invalid
|
|
100
|
-
|
|
101
|
-
describe "with invalid class" do
|
|
102
|
-
before do
|
|
103
|
-
@task_body = { "class" => "NestedDemo::TestJobY", "args" => [56] }
|
|
104
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
105
|
-
@task.expects(:delete).never
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "should raise an exception" do
|
|
109
|
-
@job = Backburner::Job.new(@task)
|
|
110
|
-
assert_raises(Backburner::Job::JobNotFound) { @job.process }
|
|
111
|
-
end # error class
|
|
112
|
-
end # invalid
|
|
113
|
-
end # process
|
|
114
|
-
|
|
115
|
-
describe "for simple delegation method" do
|
|
116
|
-
describe "with valid class" do
|
|
117
|
-
before do
|
|
118
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
119
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
120
|
-
@task.expects(:bury).once
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "should call bury for task" do
|
|
124
|
-
@job = Backburner::Job.new(@task)
|
|
125
|
-
@job.bury
|
|
126
|
-
end # bury
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe "with invalid class" do
|
|
130
|
-
before do
|
|
131
|
-
@task_body = { "class" => "AnUnknownClass", "args" => [] }
|
|
132
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true, :release => true)
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it "should call bury for task" do
|
|
136
|
-
@task.expects(:bury).once
|
|
137
|
-
@job = Backburner::Job.new(@task)
|
|
138
|
-
Backburner::Hooks.expects(:invoke_hook_events)
|
|
139
|
-
.with("AnUnknownClass", :on_bury, anything)
|
|
140
|
-
@job.bury
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it "should call retry for task" do
|
|
144
|
-
@task.expects(:release).once
|
|
145
|
-
@job = Backburner::Job.new(@task)
|
|
146
|
-
Backburner::Hooks.expects(:invoke_hook_events)
|
|
147
|
-
.with("AnUnknownClass", :on_retry, 0, is_a(Integer), anything)
|
|
148
|
-
@job.retry(0, 0)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end # simple delegation
|
|
152
|
-
|
|
153
|
-
describe "timing out for various values of ttr" do
|
|
154
|
-
before do
|
|
155
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
describe "when ttr == 0" do
|
|
159
|
-
it "should use 0 for the timeout" do
|
|
160
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 0)
|
|
161
|
-
@job = Backburner::Job.new(@task)
|
|
162
|
-
Timeout.expects(:timeout).with(0)
|
|
163
|
-
@job.process
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
describe "when ttr == 1" do
|
|
168
|
-
it "should use 1 for the timeout" do
|
|
169
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 1)
|
|
170
|
-
@job = Backburner::Job.new(@task)
|
|
171
|
-
Timeout.expects(:timeout).with(1)
|
|
172
|
-
@job.process
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "when ttr > 1" do
|
|
177
|
-
it "should use ttr-1 for the timeout" do
|
|
178
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 2)
|
|
179
|
-
@job = Backburner::Job.new(@task)
|
|
180
|
-
Timeout.expects(:timeout).with(1)
|
|
181
|
-
@job.process
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
end
|
data/test/logger_test.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe "Backburner::Logger module" do
|
|
4
|
-
include Backburner::Logger
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
@strio = StringIO.new
|
|
8
|
-
@logger = Logger.new(@strio)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "for log_info method" do
|
|
12
|
-
it "prints out to std out" do
|
|
13
|
-
output = capture_stdout { log_info("foo") }
|
|
14
|
-
assert_equal "foo\n", output
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "can be configured to log to logger" do
|
|
18
|
-
Backburner.configure { |config| config.logger = @logger }
|
|
19
|
-
log_info("foo")
|
|
20
|
-
assert_match(/I,.*?foo/, @strio.string)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
after do
|
|
24
|
-
Backburner.configure { |config| config.logger = nil }
|
|
25
|
-
end
|
|
26
|
-
end # log_info
|
|
27
|
-
|
|
28
|
-
describe "for log_error method" do
|
|
29
|
-
it "prints out to std err" do
|
|
30
|
-
output = capture_stdout { log_error("bar") }
|
|
31
|
-
assert_equal "bar\n", output
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "can be configured to log to logger" do
|
|
35
|
-
Backburner.configure { |config| config.logger = @logger }
|
|
36
|
-
log_error("bar")
|
|
37
|
-
assert_match(/E,.*?bar/, @strio.string)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
after do
|
|
41
|
-
Backburner.configure { |config| config.logger = nil }
|
|
42
|
-
end
|
|
43
|
-
end # log_error
|
|
44
|
-
end
|