backburner 1.8.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 +24 -4
- data/README.md +70 -14
- data/lib/active_job/queue_adapters/backburner_adapter.rb +9 -2
- data/lib/backburner/cli.rb +1 -1
- data/lib/backburner/enqueue_pool.rb +2 -0
- data/lib/backburner/performable.rb +28 -3
- data/lib/backburner/version.rb +1 -1
- data/lib/backburner/worker.rb +38 -4
- data/lib/backburner/workers/threading.rb +16 -0
- data/lib/backburner/workers/threads_on_fork.rb +1 -0
- metadata +8 -82
- data/.github/workflows/ci.yml +0 -45
- data/.github/workflows/github-release.yml +0 -58
- data/.github/workflows/release.yml +0 -221
- data/.gitignore +0 -17
- data/CONTRIBUTING.md +0 -37
- data/Gemfile +0 -7
- data/Rakefile +0 -17
- data/TODO +0 -4
- data/backburner.gemspec +0 -31
- 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/active_job_adapter_test.rb +0 -24
- data/test/async_proxy_test.rb +0 -36
- data/test/back_burner_test.rb +0 -101
- data/test/connection_test.rb +0 -201
- data/test/fixtures/active_job_app.rb +0 -53
- data/test/fixtures/active_jobs.rb +0 -11
- data/test/fixtures/autoload/test_broken_name_job.rb +0 -4
- data/test/fixtures/autoload/test_broken_no_method_job.rb +0 -4
- data/test/fixtures/autoload/test_broken_require_job.rb +0 -4
- data/test/fixtures/autoload/test_broken_runtime_job.rb +0 -4
- data/test/fixtures/autoload/test_broken_syntax_job.rb +0 -4
- data/test/fixtures/autoload/test_broken_timeout_job.rb +0 -4
- data/test/fixtures/autoload/test_same_name_job.rb +0 -5
- data/test/fixtures/hooked.rb +0 -122
- data/test/fixtures/test_fork_jobs.rb +0 -77
- data/test/fixtures/test_forking_jobs.rb +0 -56
- data/test/fixtures/test_jobs.rb +0 -140
- data/test/fixtures/test_queue_settings.rb +0 -54
- data/test/helpers/templogger.rb +0 -22
- data/test/helpers_test.rb +0 -462
- data/test/hooks_test.rb +0 -112
- data/test/job_test.rb +0 -207
- data/test/logger_test.rb +0 -71
- data/test/performable_test.rb +0 -138
- data/test/queue_test.rb +0 -132
- data/test/test_helper.rb +0 -182
- data/test/worker_test.rb +0 -502
- data/test/workers/forking_worker_test.rb +0 -199
- data/test/workers/simple_worker_test.rb +0 -622
- data/test/workers/threading_worker_test.rb +0 -125
- data/test/workers/threads_on_fork_worker_test.rb +0 -751
data/test/job_test.rb
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
require File.expand_path('../fixtures/test_jobs', __FILE__)
|
|
3
|
-
|
|
4
|
-
module NestedDemo
|
|
5
|
-
class TestJobC
|
|
6
|
-
def self.perform(x); puts "Performed #{x} in #{self}"; end
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class TestJobD
|
|
10
|
-
include Backburner::Queue
|
|
11
|
-
def self.perform(x); raise RuntimeError; end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "Backburner::Job module" do
|
|
16
|
-
describe "for initialize" do
|
|
17
|
-
describe "with hash" do
|
|
18
|
-
before do
|
|
19
|
-
@task = stub(:body => task_body, :ttr => 120, :delete => true, :bury => true)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "with string keys" do
|
|
23
|
-
let(:task_body) { { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] } }
|
|
24
|
-
it "should create job with correct task data" do
|
|
25
|
-
@job = Backburner::Job.new(@task)
|
|
26
|
-
assert_equal @task, @job.task
|
|
27
|
-
assert_equal ["class", "args"], @job.body.keys
|
|
28
|
-
assert_equal task_body["class"], @job.name
|
|
29
|
-
assert_equal task_body["args"], @job.args
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "with symbol keys" do
|
|
34
|
-
let(:task_body) { { :class => "NewsletterSender", :args => ["foo@bar.com", "bar@foo.com"] } }
|
|
35
|
-
it "should create job with correct task data" do
|
|
36
|
-
@job = Backburner::Job.new(@task)
|
|
37
|
-
assert_equal @task, @job.task
|
|
38
|
-
assert_equal [:class, :args], @job.body.keys
|
|
39
|
-
assert_equal task_body[:class], @job.name
|
|
40
|
-
assert_equal task_body[:args], @job.args
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end # with hash
|
|
44
|
-
|
|
45
|
-
describe "with json string" do
|
|
46
|
-
before do
|
|
47
|
-
@task_body = { "class" => "NewsletterSender", "args" => ["foo@bar.com", "bar@foo.com"] }
|
|
48
|
-
@task = stub(:body => @task_body.to_json, :ttr => 120, :delete => true, :bury => true)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should create job with correct task data" do
|
|
52
|
-
@job = Backburner::Job.new(@task)
|
|
53
|
-
assert_equal @task, @job.task
|
|
54
|
-
assert_equal ["class", "args"], @job.body.keys
|
|
55
|
-
assert_equal @task_body["class"], @job.name
|
|
56
|
-
assert_equal @task_body["args"], @job.args
|
|
57
|
-
end
|
|
58
|
-
end # with json
|
|
59
|
-
|
|
60
|
-
describe "with invalid string" do
|
|
61
|
-
before do
|
|
62
|
-
@task_body = "^%$*&^*"
|
|
63
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "should raise a job format exception" do
|
|
67
|
-
assert_raises(Backburner::Job::JobFormatInvalid) {
|
|
68
|
-
@job = Backburner::Job.new(@task)
|
|
69
|
-
}
|
|
70
|
-
end
|
|
71
|
-
end # invalid
|
|
72
|
-
end # initialize
|
|
73
|
-
|
|
74
|
-
describe "for process method" do
|
|
75
|
-
describe "with valid task" do
|
|
76
|
-
before do
|
|
77
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
78
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
79
|
-
@task.expects(:delete).once
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "should process task" do
|
|
83
|
-
@job = Backburner::Job.new(@task)
|
|
84
|
-
out = silenced(1) { @job.process }
|
|
85
|
-
assert_match(/Performed 56 in NestedDemo::TestJobC/, out)
|
|
86
|
-
end # process
|
|
87
|
-
end # valid
|
|
88
|
-
|
|
89
|
-
describe "with invalid task" do
|
|
90
|
-
before do
|
|
91
|
-
@task_body = { "class" => "NestedDemo::TestJobD", "args" => [56] }
|
|
92
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
93
|
-
@task.expects(:delete).never
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "should raise an exception" do
|
|
97
|
-
@job = Backburner::Job.new(@task)
|
|
98
|
-
assert_raises(RuntimeError) { @job.process }
|
|
99
|
-
end # error invalid
|
|
100
|
-
end # invalid
|
|
101
|
-
|
|
102
|
-
describe "with invalid class" do
|
|
103
|
-
before do
|
|
104
|
-
@task_body = { "class" => "NestedDemo::TestJobY", "args" => [56] }
|
|
105
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
106
|
-
@task.expects(:delete).never
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "should raise an exception" do
|
|
110
|
-
@job = Backburner::Job.new(@task)
|
|
111
|
-
assert_raises(Backburner::Job::JobNotFound) { @job.process }
|
|
112
|
-
end # error class
|
|
113
|
-
end # invalid
|
|
114
|
-
|
|
115
|
-
describe "with a class an autoloader can't load" do
|
|
116
|
-
before do
|
|
117
|
-
@task_body = { "class" => "AutoloadingDemo::TestJobGone", "args" => [56] }
|
|
118
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
119
|
-
@task.expects(:delete).never
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "should raise JobNotFound" do
|
|
123
|
-
@job = Backburner::Job.new(@task)
|
|
124
|
-
assert_raises(Backburner::Job::JobNotFound) { @job.process }
|
|
125
|
-
end
|
|
126
|
-
end # autoloader
|
|
127
|
-
|
|
128
|
-
describe "with a class whose file fails to load" do
|
|
129
|
-
it "should raise JobNotFound naming the cause on one line" do
|
|
130
|
-
task = stub(:body => { "class" => "TestBrokenNameJob", "args" => [56] }, :ttr => 120, :delete => true, :bury => true)
|
|
131
|
-
error = assert_raises(Backburner::Job::JobNotFound) { Backburner::Job.new(task).process }
|
|
132
|
-
assert_match(/\ATestBrokenNameJob \(NameError: uninitialized constant (TestBrokenNameJob::)?TestMissingConcern\)\z/, error.message)
|
|
133
|
-
end
|
|
134
|
-
end # broken class file
|
|
135
|
-
end # process
|
|
136
|
-
|
|
137
|
-
describe "for simple delegation method" do
|
|
138
|
-
describe "with valid class" do
|
|
139
|
-
before do
|
|
140
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
141
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true)
|
|
142
|
-
@task.expects(:bury).once
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "should call bury for task" do
|
|
146
|
-
@job = Backburner::Job.new(@task)
|
|
147
|
-
@job.bury
|
|
148
|
-
end # bury
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe "with invalid class" do
|
|
152
|
-
before do
|
|
153
|
-
@task_body = { "class" => "AnUnknownClass", "args" => [] }
|
|
154
|
-
@task = stub(:body => @task_body, :ttr => 120, :delete => true, :bury => true, :release => true)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "should call bury for task" do
|
|
158
|
-
@task.expects(:bury).once
|
|
159
|
-
@job = Backburner::Job.new(@task)
|
|
160
|
-
Backburner::Hooks.expects(:invoke_hook_events)
|
|
161
|
-
.with("AnUnknownClass", :on_bury, anything)
|
|
162
|
-
@job.bury
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it "should call retry for task" do
|
|
166
|
-
@task.expects(:release).once
|
|
167
|
-
@job = Backburner::Job.new(@task)
|
|
168
|
-
Backburner::Hooks.expects(:invoke_hook_events)
|
|
169
|
-
.with("AnUnknownClass", :on_retry, 0, is_a(Integer), anything)
|
|
170
|
-
@job.retry(0, 0)
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end # simple delegation
|
|
174
|
-
|
|
175
|
-
describe "timing out for various values of ttr" do
|
|
176
|
-
before do
|
|
177
|
-
@task_body = { "class" => "NestedDemo::TestJobC", "args" => [56] }
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
describe "when ttr == 0" do
|
|
181
|
-
it "should use 0 for the timeout" do
|
|
182
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 0)
|
|
183
|
-
@job = Backburner::Job.new(@task)
|
|
184
|
-
Timeout.expects(:timeout).with(0)
|
|
185
|
-
@job.process
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
describe "when ttr == 1" do
|
|
190
|
-
it "should use 1 for the timeout" do
|
|
191
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 1)
|
|
192
|
-
@job = Backburner::Job.new(@task)
|
|
193
|
-
Timeout.expects(:timeout).with(1)
|
|
194
|
-
@job.process
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
describe "when ttr > 1" do
|
|
199
|
-
it "should use ttr-1 for the timeout" do
|
|
200
|
-
@task = stub(:body => @task_body, :delete => true, :ttr => 2)
|
|
201
|
-
@job = Backburner::Job.new(@task)
|
|
202
|
-
Timeout.expects(:timeout).with(1)
|
|
203
|
-
@job.process
|
|
204
|
-
end
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
end
|
data/test/logger_test.rb
DELETED
|
@@ -1,71 +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
|
-
|
|
45
|
-
describe "for log_warn method" do
|
|
46
|
-
it "prints out to std err" do
|
|
47
|
-
output = capture_stdout { log_warn("baz") }
|
|
48
|
-
assert_equal "baz\n", output
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "can be configured to log to logger" do
|
|
52
|
-
Backburner.configure { |config| config.logger = @logger }
|
|
53
|
-
log_warn("baz")
|
|
54
|
-
assert_match(/W,.*?baz/, @strio.string)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "logs as an error to a logger without a public warn method" do
|
|
58
|
-
logged = []
|
|
59
|
-
logger = Object.new # the README asks a logger for info and error only
|
|
60
|
-
logger.define_singleton_method(:info) { |msg| logged << [:info, msg] }
|
|
61
|
-
logger.define_singleton_method(:error) { |msg| logged << [:error, msg] }
|
|
62
|
-
Backburner.configure { |config| config.logger = logger }
|
|
63
|
-
log_warn("baz")
|
|
64
|
-
assert_equal [[:error, "baz"]], logged
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
after do
|
|
68
|
-
Backburner.configure { |config| config.logger = nil }
|
|
69
|
-
end
|
|
70
|
-
end # log_warn
|
|
71
|
-
end
|
data/test/performable_test.rb
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
class TestObj
|
|
4
|
-
ID = 56
|
|
5
|
-
def id; ID; end
|
|
6
|
-
def self.find(id); TestObj.new if id == ID; end
|
|
7
|
-
def foo(state, state2); "bar #{state} #{state2}"; end
|
|
8
|
-
def self.bar(state, state2); "baz #{state} #{state2}"; end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class PerformableTestObj < TestObj
|
|
12
|
-
include Backburner::Performable
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
class AutomagicTestObj < TestObj
|
|
16
|
-
# Don't include Backburner::Performable because it should be automagically included
|
|
17
|
-
def qux(state, state2); "garply #{state} #{state2}" end
|
|
18
|
-
def self.garply(state, state2); "thud #{state} #{state2}" end
|
|
19
|
-
def qux?; "garply!" end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class AsyncInstanceMethodsTestObj < PerformableTestObj; end
|
|
23
|
-
class AsyncStaticMethodsTestObj < PerformableTestObj; end
|
|
24
|
-
|
|
25
|
-
class AsyncSettingsTestObj < TestObj
|
|
26
|
-
include Backburner::Performable
|
|
27
|
-
queue "performable-settings"
|
|
28
|
-
queue_priority 10
|
|
29
|
-
queue_respond_timeout 300
|
|
30
|
-
queue_max_job_retries 3
|
|
31
|
-
handle_asynchronously :foo
|
|
32
|
-
handle_static_asynchronously :bar
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
class QueueThenPerformableTestObj < TestObj
|
|
36
|
-
include Backburner::Queue
|
|
37
|
-
queue "queue-then-performable"
|
|
38
|
-
queue_priority 20
|
|
39
|
-
queue_respond_timeout 200
|
|
40
|
-
include Backburner::Performable
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
describe "Backburner::Performable module" do
|
|
46
|
-
after { ENV["TEST"] = nil }
|
|
47
|
-
|
|
48
|
-
describe "for async instance method" do
|
|
49
|
-
it "should invoke worker enqueue" do
|
|
50
|
-
Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [56, :foo, true, false], has_entries(:pri => 5000, :queue => "foo"))
|
|
51
|
-
PerformableTestObj.new.async(:pri => 5000, :queue => "foo").foo(true, false)
|
|
52
|
-
end
|
|
53
|
-
end # async instance
|
|
54
|
-
|
|
55
|
-
describe "for async class method" do
|
|
56
|
-
it "should invoke worker enqueue" do
|
|
57
|
-
Backburner::Worker.expects(:enqueue).with(PerformableTestObj, [nil, :bar, true, false], has_entries(:pri => 5000, :queue => "foo"))
|
|
58
|
-
PerformableTestObj.async(:pri => 5000, :queue => "foo").bar(true, false)
|
|
59
|
-
end
|
|
60
|
-
end # async class
|
|
61
|
-
|
|
62
|
-
describe "for perform class method" do
|
|
63
|
-
it "should work for instance" do
|
|
64
|
-
assert_equal "bar true false", PerformableTestObj.perform(PerformableTestObj::ID, :foo, true, false)
|
|
65
|
-
end # instance
|
|
66
|
-
|
|
67
|
-
it "should work for class level" do
|
|
68
|
-
assert_equal "baz false true", PerformableTestObj.perform(nil, :bar, false, true)
|
|
69
|
-
end # class
|
|
70
|
-
end # perform
|
|
71
|
-
|
|
72
|
-
describe "for handle_asynchronously class method" do
|
|
73
|
-
it "should automagically asynchronously proxy calls to the method" do
|
|
74
|
-
Backburner::Performable.handle_asynchronously(AutomagicTestObj, :qux, :pri => 5000, :queue => "qux")
|
|
75
|
-
|
|
76
|
-
Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [56, :qux_without_async, true, false], has_entries(:pri => 5000, :queue => "qux"))
|
|
77
|
-
AutomagicTestObj.new.qux(true, false)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "should work for class methods, too" do
|
|
81
|
-
Backburner::Performable.handle_static_asynchronously(AutomagicTestObj, :garply, :pri => 5000, :queue => "garply")
|
|
82
|
-
|
|
83
|
-
Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [nil, :garply_without_async, true, false], has_entries(:pri => 5000, :queue => "garply"))
|
|
84
|
-
AutomagicTestObj.garply(true, false)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "should correctly handle punctuation" do
|
|
88
|
-
Backburner::Performable.handle_asynchronously(AutomagicTestObj, :qux?)
|
|
89
|
-
|
|
90
|
-
Backburner::Worker.expects(:enqueue).with(AutomagicTestObj, [56, :qux_without_async?], {})
|
|
91
|
-
AutomagicTestObj.new.qux?
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "should be available for instance methods on any class that includes the Performable module" do
|
|
95
|
-
AsyncInstanceMethodsTestObj.handle_asynchronously :foo, pri: 5000, queue: 'qux'
|
|
96
|
-
Backburner::Worker.expects(:enqueue).with(AsyncInstanceMethodsTestObj, [56, :foo_without_async, true, false], has_entries(:pri => 5000, :queue => "qux"))
|
|
97
|
-
AsyncInstanceMethodsTestObj.new.foo(true, false)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should be available for class methods on any class that includes the Performable module" do
|
|
101
|
-
AsyncStaticMethodsTestObj.handle_static_asynchronously :bar, pri: 5000, queue: 'garply'
|
|
102
|
-
Backburner::Worker.expects(:enqueue).with(AsyncStaticMethodsTestObj, [nil, :bar_without_async, true, false], has_entries(:pri => 5000, :queue => "garply"))
|
|
103
|
-
AsyncStaticMethodsTestObj.bar(true, false)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
describe "on a class with queue settings" do
|
|
107
|
-
before { clear_jobs!("performable-settings") }
|
|
108
|
-
after { clear_jobs!("performable-settings") }
|
|
109
|
-
|
|
110
|
-
it "keeps the class's queue settings" do
|
|
111
|
-
assert_equal "performable-settings", AsyncSettingsTestObj.queue
|
|
112
|
-
assert_equal 10, AsyncSettingsTestObj.queue_priority
|
|
113
|
-
assert_equal 300, AsyncSettingsTestObj.queue_respond_timeout
|
|
114
|
-
assert_equal 3, AsyncSettingsTestObj.queue_max_job_retries
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "enqueues instance and class method calls with the class's queue settings" do
|
|
118
|
-
AsyncSettingsTestObj.new.foo(true, false)
|
|
119
|
-
AsyncSettingsTestObj.bar(false, true)
|
|
120
|
-
[[56, "foo_without_async", true, false], [nil, "bar_without_async", false, true]].each do |args|
|
|
121
|
-
pop_one_job("performable-settings") do |job, body|
|
|
122
|
-
assert_equal ["AsyncSettingsTestObj", args], [body["class"], body["args"]]
|
|
123
|
-
assert_equal [10, 300], [job.pri, job.ttr]
|
|
124
|
-
job.delete
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
end # handle_asynchronously
|
|
130
|
-
|
|
131
|
-
describe "when included after Backburner::Queue" do
|
|
132
|
-
it "keeps the queue settings the class already set" do
|
|
133
|
-
assert_equal "queue-then-performable", QueueThenPerformableTestObj.queue
|
|
134
|
-
assert_equal 20, QueueThenPerformableTestObj.queue_priority
|
|
135
|
-
assert_equal 200, QueueThenPerformableTestObj.queue_respond_timeout
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
data/test/queue_test.rb
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
module NestedDemo
|
|
4
|
-
class TestJobA; include Backburner::Queue; end
|
|
5
|
-
class TestJobB; include Backburner::Queue; end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
module InheritDemo
|
|
9
|
-
class ParentJob
|
|
10
|
-
include Backburner::Queue
|
|
11
|
-
queue "inherit-parent"
|
|
12
|
-
queue_priority 10
|
|
13
|
-
queue_respond_timeout 77
|
|
14
|
-
queue_max_job_retries 4
|
|
15
|
-
queue_retry_delay 9
|
|
16
|
-
queue_retry_delay_proc lambda { |min_retry_delay, num_retries| 42 }
|
|
17
|
-
queue_jobs_limit 3
|
|
18
|
-
queue_garbage_limit 50
|
|
19
|
-
queue_retry_limit 6
|
|
20
|
-
end
|
|
21
|
-
class ChildJob < ParentJob; end
|
|
22
|
-
class GrandchildJob < ChildJob; end
|
|
23
|
-
class OverrideJob < ParentJob
|
|
24
|
-
queue "inherit-override"
|
|
25
|
-
queue_priority 20
|
|
26
|
-
end
|
|
27
|
-
class ReincludedJob < ParentJob; include Backburner::Queue; end
|
|
28
|
-
class LambdaParentJob
|
|
29
|
-
include Backburner::Queue
|
|
30
|
-
queue lambda { |klass| klass.name }
|
|
31
|
-
end
|
|
32
|
-
class LambdaChildJob < LambdaParentJob; end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe "Backburner::Queue module" do
|
|
36
|
-
describe "contains known_queue_classes" do
|
|
37
|
-
it "has all defined known queues" do
|
|
38
|
-
assert_contains Backburner::Worker.known_queue_classes, NestedDemo::TestJobA
|
|
39
|
-
assert_contains Backburner::Worker.known_queue_classes, NestedDemo::TestJobB
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "for queue method accessor" do
|
|
44
|
-
it "should return the queue name" do
|
|
45
|
-
assert_equal Backburner.configuration.primary_queue, NestedDemo::TestJobA.queue
|
|
46
|
-
end
|
|
47
|
-
end # queue_name
|
|
48
|
-
|
|
49
|
-
describe "for queue assignment method" do
|
|
50
|
-
it "should allow queue name to be assigned" do
|
|
51
|
-
NestedDemo::TestJobB.queue("nested/job")
|
|
52
|
-
assert_equal "nested/job", NestedDemo::TestJobB.queue
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "should allow lambdas" do
|
|
56
|
-
NestedDemo::TestJobB.queue(lambda { |klass| klass.name })
|
|
57
|
-
assert_equal "NestedDemo::TestJobB", NestedDemo::TestJobB.queue
|
|
58
|
-
end
|
|
59
|
-
end # queue
|
|
60
|
-
|
|
61
|
-
describe "for queue_priority assignment method" do
|
|
62
|
-
it "should allow queue priority to be assigned" do
|
|
63
|
-
NestedDemo::TestJobB.queue_priority(1000)
|
|
64
|
-
assert_equal 1000, NestedDemo::TestJobB.queue_priority
|
|
65
|
-
end
|
|
66
|
-
end # queue_priority
|
|
67
|
-
|
|
68
|
-
describe "for queue_respond_timeout assignment method" do
|
|
69
|
-
it "should allow queue respond_timeout to be assigned" do
|
|
70
|
-
NestedDemo::TestJobB.queue_respond_timeout(300)
|
|
71
|
-
assert_equal 300, NestedDemo::TestJobB.queue_respond_timeout
|
|
72
|
-
end
|
|
73
|
-
end # queue_respond_timeout
|
|
74
|
-
|
|
75
|
-
describe "for queue_max_job_retries assignment method" do
|
|
76
|
-
it "should allow queue max_job_retries to be assigned" do
|
|
77
|
-
NestedDemo::TestJobB.queue_max_job_retries(5)
|
|
78
|
-
assert_equal 5, NestedDemo::TestJobB.queue_max_job_retries
|
|
79
|
-
end
|
|
80
|
-
end # queue_max_job_retries
|
|
81
|
-
|
|
82
|
-
describe "for queue_retry_delay assignment method" do
|
|
83
|
-
it "should allow queue retry_delay to be assigned" do
|
|
84
|
-
NestedDemo::TestJobB.queue_retry_delay(300)
|
|
85
|
-
assert_equal 300, NestedDemo::TestJobB.queue_retry_delay
|
|
86
|
-
end
|
|
87
|
-
end # queue_retry_delay
|
|
88
|
-
|
|
89
|
-
describe "for queue_retry_delay_proc assignment method" do
|
|
90
|
-
it "should allow queue retry_delay_proc to be assigned" do
|
|
91
|
-
retry_delay_proc = lambda { |x, y| x - y }
|
|
92
|
-
NestedDemo::TestJobB.queue_retry_delay_proc(retry_delay_proc)
|
|
93
|
-
assert_equal retry_delay_proc.call(2, 1), NestedDemo::TestJobB.queue_retry_delay_proc.call(2, 1)
|
|
94
|
-
end
|
|
95
|
-
end # queue_retry_delay_proc
|
|
96
|
-
|
|
97
|
-
describe "for subclasses" do
|
|
98
|
-
settings = [:queue, :queue_priority, :queue_respond_timeout, :queue_max_job_retries, :queue_retry_delay,
|
|
99
|
-
:queue_retry_delay_proc, :queue_jobs_limit, :queue_garbage_limit, :queue_retry_limit]
|
|
100
|
-
|
|
101
|
-
it "inherits every queue setting from the superclass" do
|
|
102
|
-
settings.each do |setting|
|
|
103
|
-
refute_nil InheritDemo::ParentJob.send(setting), setting
|
|
104
|
-
assert_equal InheritDemo::ParentJob.send(setting), InheritDemo::ChildJob.send(setting), setting
|
|
105
|
-
assert_equal InheritDemo::ParentJob.send(setting), InheritDemo::GrandchildJob.send(setting), setting
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "uses its own settings over inherited ones without changing the superclass" do
|
|
110
|
-
assert_equal "inherit-override", InheritDemo::OverrideJob.queue
|
|
111
|
-
assert_equal 20, InheritDemo::OverrideJob.queue_priority
|
|
112
|
-
assert_equal 77, InheritDemo::OverrideJob.queue_respond_timeout
|
|
113
|
-
assert_equal "inherit-parent", InheritDemo::ParentJob.queue
|
|
114
|
-
assert_equal 10, InheritDemo::ParentJob.queue_priority
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "inherits the superclass settings when it includes Backburner::Queue again" do
|
|
118
|
-
assert_equal "inherit-parent", InheritDemo::ReincludedJob.queue
|
|
119
|
-
assert_equal 10, InheritDemo::ReincludedJob.queue_priority
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "calls an inherited queue lambda with the subclass" do
|
|
123
|
-
assert_equal "InheritDemo::LambdaChildJob", InheritDemo::LambdaChildJob.queue
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "registers subclasses as known queue classes, once each" do
|
|
127
|
-
[InheritDemo::ChildJob, InheritDemo::GrandchildJob, InheritDemo::OverrideJob, InheritDemo::ReincludedJob].each do |klass|
|
|
128
|
-
assert_equal 1, Backburner::Worker.known_queue_classes.count(klass), klass.name
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end # subclasses
|
|
132
|
-
end # Backburner::Queue
|