boss_queue 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/boss_queue.gemspec +2 -2
- data/lib/boss_queue/job.rb +21 -3
- data/spec/job_spec.rb +89 -16
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/boss_queue.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "boss_queue"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Nelson"]
|
12
|
-
s.date = "2013-10-
|
12
|
+
s.date = "2013-10-15"
|
13
13
|
s.description = "A fault tolerant job queue built around Amazon SQS & DynamoDB"
|
14
14
|
s.email = "daniel@populr.me"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/boss_queue/job.rb
CHANGED
@@ -6,6 +6,8 @@ class BossQueue
|
|
6
6
|
attr_accessor :queue_name
|
7
7
|
|
8
8
|
boolean_attr :failed
|
9
|
+
boolean_attr :target_missing
|
10
|
+
boolean_attr :delete_if_target_missing
|
9
11
|
|
10
12
|
string_attr :model_class_name
|
11
13
|
string_attr :model_id
|
@@ -73,15 +75,27 @@ class BossQueue
|
|
73
75
|
self.exception_message = err.message
|
74
76
|
self.stacktrace = err.backtrace[0, 7].join("\n")
|
75
77
|
|
76
|
-
|
78
|
+
failed_target = target rescue nil
|
79
|
+
|
80
|
+
if failed_target.nil?
|
81
|
+
if delete_if_target_missing?
|
82
|
+
destroy
|
83
|
+
else
|
84
|
+
self.failed = true
|
85
|
+
self.target_missing = true
|
86
|
+
self.save!
|
87
|
+
end
|
88
|
+
|
89
|
+
elsif failure_action == 'retry' && retry_delay
|
77
90
|
enqueue_with_delay(retry_delay)
|
78
91
|
self.save!
|
79
92
|
|
80
93
|
elsif failure_action == 'callback' &&
|
81
94
|
failure_callback
|
82
95
|
|
83
|
-
|
84
|
-
|
96
|
+
|
97
|
+
delete_me = failed_target.send(failure_callback, err, *arguments)
|
98
|
+
if delete_me
|
85
99
|
destroy
|
86
100
|
else
|
87
101
|
self.failed = true
|
@@ -110,6 +124,10 @@ class BossQueue
|
|
110
124
|
end
|
111
125
|
|
112
126
|
def target
|
127
|
+
@target ||= _target
|
128
|
+
end
|
129
|
+
|
130
|
+
def _target
|
113
131
|
klass = constantize(model_class_name)
|
114
132
|
if model_id
|
115
133
|
klass.find(model_id)
|
data/spec/job_spec.rb
CHANGED
@@ -11,17 +11,48 @@ describe "BossQueue::Job" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
it "should respond to target_missing?" do
|
16
|
+
BossQueue::Job.new.should respond_to(:target_missing?)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should respond to target_missing=" do
|
20
|
+
BossQueue::Job.new.should respond_to(:target_missing=)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#target_missing?" do
|
24
|
+
it "should default to false" do
|
25
|
+
BossQueue::Job.new.target_missing?.should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
it "should respond to delete_if_target_missing?" do
|
31
|
+
BossQueue::Job.new.should respond_to(:delete_if_target_missing?)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should respond to delete_if_target_missing=" do
|
35
|
+
BossQueue::Job.new.should respond_to(:delete_if_target_missing=)
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#delete_if_target_missing?" do
|
39
|
+
it "should default to false" do
|
40
|
+
BossQueue::Job.new.delete_if_target_missing?.should be_false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it "should respond to failed?" do
|
46
|
+
BossQueue::Job.new.should respond_to(:failed?)
|
16
47
|
end
|
17
48
|
|
18
49
|
it "should respond to failed=" do
|
19
50
|
BossQueue::Job.new.should respond_to(:failed=)
|
20
51
|
end
|
21
52
|
|
22
|
-
describe "#failed" do
|
53
|
+
describe "#failed?" do
|
23
54
|
it "should default to false" do
|
24
|
-
BossQueue::Job.new.failed
|
55
|
+
BossQueue::Job.new.failed?.should be_false
|
25
56
|
end
|
26
57
|
end
|
27
58
|
|
@@ -284,10 +315,24 @@ describe "BossQueue::Job" do
|
|
284
315
|
|
285
316
|
describe "#fail" do
|
286
317
|
before(:each) do
|
318
|
+
@instance_to_work_on = double('instance_to_work_on')
|
319
|
+
@instance_to_work_on.stub(:test_instance_method)
|
320
|
+
@instance_to_work_on.stub(:failure).and_return(false)
|
321
|
+
TestClass.stub(:find).and_return(@instance_to_work_on)
|
322
|
+
|
287
323
|
@job = BossQueue::Job.new
|
288
324
|
@job.stub(:retry_delay).and_return(nil)
|
289
325
|
@job.stub(:save!)
|
290
326
|
@job.stub(:enqueue_with_delay)
|
327
|
+
|
328
|
+
@job.stub(:destroy)
|
329
|
+
@job.model_class_name = 'TestClass'
|
330
|
+
@job.model_id = 'xyz'
|
331
|
+
@job.callback = 'test_instance_method'
|
332
|
+
@arguments = ['a', 'b', { 'c' => 2, 'd' => 1 }]
|
333
|
+
@argument_json = JSON.generate(@arguments)
|
334
|
+
@job.args = @argument_json
|
335
|
+
|
291
336
|
@err
|
292
337
|
begin
|
293
338
|
raise StandardError.new('hello world')
|
@@ -316,22 +361,50 @@ describe "BossQueue::Job" do
|
|
316
361
|
@job.fail(@err)
|
317
362
|
end
|
318
363
|
|
319
|
-
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
context "when delete_if_target_missing is true and the target cannot be found" do
|
369
|
+
it "should destroy the record" do
|
370
|
+
@job.failure_action = 'callback'
|
371
|
+
@job.failure_callback = 'failure'
|
372
|
+
@job.delete_if_target_missing = true
|
373
|
+
TestClass.stub(:find).and_raise('not found')
|
374
|
+
|
375
|
+
@job.should_receive(:destroy)
|
376
|
+
@job.fail(@err)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
context "when delete_if_target_missing is false and the target cannot be found" do
|
320
384
|
before(:each) do
|
321
385
|
@job.failure_action = 'callback'
|
322
386
|
@job.failure_callback = 'failure'
|
387
|
+
TestClass.stub(:find).and_raise('not found')
|
388
|
+
end
|
323
389
|
|
324
|
-
|
325
|
-
@job.
|
326
|
-
@job.
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
@job.
|
331
|
-
@
|
332
|
-
|
333
|
-
|
334
|
-
|
390
|
+
it "should set target_missing on the job" do
|
391
|
+
@job.fail(@err)
|
392
|
+
@job.target_missing.should be_true
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should not destroy the record" do
|
396
|
+
@job.should_not_receive(:destroy)
|
397
|
+
@job.fail(@err)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
|
404
|
+
context "when failure_action is 'callback'" do
|
405
|
+
before(:each) do
|
406
|
+
@job.failure_action = 'callback'
|
407
|
+
@job.failure_callback = 'failure'
|
335
408
|
end
|
336
409
|
|
337
410
|
it "should call the failure_callback method with the exception and the callback arguments" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boss_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
segments:
|
162
162
|
- 0
|
163
|
-
hash: -
|
163
|
+
hash: -3544343806450601850
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
165
|
none: false
|
166
166
|
requirements:
|