boss_queue 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/VERSION +1 -1
- data/boss_queue.gemspec +1 -1
- data/lib/boss_queue/boss_queue.rb +6 -0
- data/spec/boss_queue_spec.rb +17 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -67,10 +67,16 @@ Usage
|
|
67
67
|
myobject = MyClass.new
|
68
68
|
# default failure action is 'retry' which retries up to four times
|
69
69
|
queue = BossQueue.new(:failure_action => 'none', :queue => 'emails')
|
70
|
+
|
70
71
|
# or we can set up a callback method to be called on the enqueued class / object
|
71
72
|
# when there is a failure
|
72
73
|
queue = BossQueue.new(:failure_action => 'callback', :failure_callback => :method_to_execute_on_failure, :queue => 'emails')
|
73
74
|
|
75
|
+
# by default, BossQueue will record a failed job if the target cannot be found
|
76
|
+
# when the background job runs; the job can be deleted instead by including a
|
77
|
+
# :delete_if_target_missing => true option
|
78
|
+
queue = BossQueue.new(:delete_if_target_missing => true, :queue => 'emails')
|
79
|
+
|
74
80
|
# can enqueue instance methods (assumes that objects have an id and a #find(id) method)
|
75
81
|
queue.enqueue(myobject, :method_to_execute, arg1, arg2)
|
76
82
|
# enqueue with a delay of up to 900 seconds (15 minutes)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/boss_queue.gemspec
CHANGED
@@ -6,6 +6,7 @@ class BossQueue
|
|
6
6
|
def initialize(options={})
|
7
7
|
@failure_action = options[:failure_action] if options[:failure_action]
|
8
8
|
@failure_callback = options[:failure_callback] if options[:failure_callback]
|
9
|
+
@delete_if_target_missing = options[:delete_if_target_missing] if options[:delete_if_target_missing]
|
9
10
|
@queue_postfix = options[:queue] ? '_' + options[:queue] : ''
|
10
11
|
end
|
11
12
|
|
@@ -21,6 +22,10 @@ class BossQueue
|
|
21
22
|
@failure_callback
|
22
23
|
end
|
23
24
|
|
25
|
+
def delete_if_target_missing
|
26
|
+
@delete_if_target_missing
|
27
|
+
end
|
28
|
+
|
24
29
|
def table_name
|
25
30
|
"#{BossQueue.queue_prefix}boss_queue_jobs"
|
26
31
|
end
|
@@ -84,6 +89,7 @@ class BossQueue
|
|
84
89
|
job.queue_name = queue_name
|
85
90
|
job.failure_action = failure_action
|
86
91
|
job.failure_callback = failure_callback.to_s if failure_action == 'callback' && failure_callback
|
92
|
+
job.delete_if_target_missing = delete_if_target_missing if delete_if_target_missing
|
87
93
|
job.model_class_name = class_name
|
88
94
|
job.model_id = instance_id unless instance_id.nil?
|
89
95
|
job.callback = callback_method.to_s
|
data/spec/boss_queue_spec.rb
CHANGED
@@ -7,6 +7,7 @@ describe "BossQueue module" do
|
|
7
7
|
BossQueue::Job.any_instance.stub(:queue_name=)
|
8
8
|
BossQueue::Job.any_instance.stub(:failure_action=)
|
9
9
|
BossQueue::Job.any_instance.stub(:failure_callback=)
|
10
|
+
BossQueue::Job.any_instance.stub(:delete_if_target_missing=)
|
10
11
|
BossQueue::Job.any_instance.stub(:model_class_name=)
|
11
12
|
BossQueue::Job.any_instance.stub(:model_id=)
|
12
13
|
BossQueue::Job.any_instance.stub(:callback=)
|
@@ -182,6 +183,14 @@ describe "BossQueue module" do
|
|
182
183
|
end
|
183
184
|
end
|
184
185
|
|
186
|
+
context "when delete_if_target_missing option is true" do
|
187
|
+
it "should set delete_if_target_missing on the job" do
|
188
|
+
queue = BossQueue.new(:delete_if_target_missing => true)
|
189
|
+
BossQueue::Job.any_instance.should_receive(:delete_if_target_missing=).with(true)
|
190
|
+
queue.enqueue(TestClass, :test_class_method, 'a', 'b', { 'c' => 2, 'd' => 1 })
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
185
194
|
end
|
186
195
|
|
187
196
|
describe "#enqueue_with_delay" do
|
@@ -228,6 +237,14 @@ describe "BossQueue module" do
|
|
228
237
|
end
|
229
238
|
end
|
230
239
|
|
240
|
+
context "when delete_if_target_missing option is true" do
|
241
|
+
it "should set delete_if_target_missing on the job" do
|
242
|
+
queue = BossQueue.new(:delete_if_target_missing => true)
|
243
|
+
BossQueue::Job.any_instance.should_receive(:delete_if_target_missing=).with(true)
|
244
|
+
queue.enqueue_with_delay(60, TestClass, :test_class_method, 'a', 'b', { 'c' => 2, 'd' => 1 })
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
231
248
|
end
|
232
249
|
|
233
250
|
describe "#work" 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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -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: -3393921957837666108
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
165
|
none: false
|
166
166
|
requirements:
|