mongo-dequeue 0.3.0 → 0.4.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.
- data/VERSION +1 -1
- data/lib/mongo-dequeue.rb +16 -6
- data/mongo-dequeue.gemspec +3 -2
- data/pkg/mongo-dequeue-0.3.0.gem +0 -0
- data/spec/mongo_dequeue_spec.rb +40 -1
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/mongo-dequeue.rb
CHANGED
@@ -50,7 +50,8 @@ class Mongo::Dequeue
|
|
50
50
|
:locked_till => nil,
|
51
51
|
:completed_at => nil,
|
52
52
|
:priority => item_opts[:priority] || @config[:default_priority],
|
53
|
-
:duplicate_key => dup_key
|
53
|
+
:duplicate_key => dup_key,
|
54
|
+
:completecount => 0
|
54
55
|
},
|
55
56
|
'$inc' => {:count => 1 }
|
56
57
|
}
|
@@ -91,8 +92,8 @@ class Mongo::Dequeue
|
|
91
92
|
begin
|
92
93
|
cmd = BSON::OrderedHash.new
|
93
94
|
cmd['findandmodify'] = collection.name
|
94
|
-
cmd['query'] = {:_id => BSON::ObjectId.from_string(id)
|
95
|
-
cmd['update'] = {'$set' => {:completed_at => Time.now.utc, :complete => true} }
|
95
|
+
cmd['query'] = {:_id => BSON::ObjectId.from_string(id)}
|
96
|
+
cmd['update'] = {'$set' => {:completed_at => Time.now.utc, :complete => true}, '$inc' => {:completecount => 1} }
|
96
97
|
cmd['limit'] = 1
|
97
98
|
collection.db.command(cmd)
|
98
99
|
rescue Mongo::OperationFailure => of
|
@@ -119,15 +120,24 @@ class Mongo::Dequeue
|
|
119
120
|
var c = db.#{collection.name}.count({'complete': true});
|
120
121
|
var t = db.#{collection.name}.count();
|
121
122
|
var l = db.#{collection.name}.count({'complete': false, 'locked_till': {'$gte':nowutc} });
|
122
|
-
|
123
|
+
var rc = db.#{collection.name}.group({
|
124
|
+
'key': {},
|
125
|
+
'cond': {'complete':true},
|
126
|
+
'$reduce': function(obj, prev){prev.count += (obj.completecount - 1);},
|
127
|
+
'initial': {count: 0}
|
128
|
+
});
|
129
|
+
|
130
|
+
return [a, c, t, l, rc[0] ? rc[0].count : 0];
|
123
131
|
}
|
124
132
|
);
|
125
133
|
}"
|
126
|
-
available, complete, total, locked = collection.db.eval(js)
|
134
|
+
available, complete, total, locked, redundant_completes = collection.db.eval(js)
|
127
135
|
{ :locked => locked.to_i,
|
128
136
|
:complete => complete.to_i,
|
129
137
|
:available => available.to_i,
|
130
|
-
:total => total.to_i
|
138
|
+
:total => total.to_i,
|
139
|
+
:redundantcompletes => redundant_completes.to_i
|
140
|
+
}
|
131
141
|
end
|
132
142
|
|
133
143
|
def self.generate_duplicate_key(body)
|
data/mongo-dequeue.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo-dequeue}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["TelegramSam"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-19}
|
13
13
|
s.description = %q{A de-duplicating priority queue that uses mongodb as the storage engine.}
|
14
14
|
s.email = %q{telegramsam@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"pkg/mongo-dequeue-0.1.0.gem",
|
29
29
|
"pkg/mongo-dequeue-0.2.0.gem",
|
30
30
|
"pkg/mongo-dequeue-0.2.1.gem",
|
31
|
+
"pkg/mongo-dequeue-0.3.0.gem",
|
31
32
|
"spec/mongo_dequeue_spec.rb",
|
32
33
|
"spec/spec_helper.rb"
|
33
34
|
]
|
Binary file
|
data/spec/mongo_dequeue_spec.rb
CHANGED
@@ -216,10 +216,46 @@ describe Mongo::Dequeue do
|
|
216
216
|
@peek.length.should == 2
|
217
217
|
end
|
218
218
|
end
|
219
|
+
|
220
|
+
describe "Completing" do
|
221
|
+
before(:all) do
|
222
|
+
@a = insert_and_inspect("a")
|
223
|
+
@b = insert_and_inspect("b")
|
224
|
+
@c = insert_and_inspect("c")
|
225
|
+
|
226
|
+
|
227
|
+
@ap = @queue.pop
|
228
|
+
@queue.complete(@ap[:id])
|
229
|
+
@ac = @queue.send(:collection).find_one({:_id => BSON::ObjectId.from_string(@ap[:id])})
|
230
|
+
|
231
|
+
@bp = @queue.pop
|
232
|
+
@bc = @queue.send(:collection).find_one({:_id => BSON::ObjectId.from_string(@bp[:id])})
|
233
|
+
|
234
|
+
@cp = @queue.pop
|
235
|
+
@queue.complete(@cp[:id])
|
236
|
+
@queue.complete(@cp[:id])
|
237
|
+
@queue.complete(@cp[:id])
|
238
|
+
@cc = @queue.send(:collection).find_one({:_id => BSON::ObjectId.from_string(@cp[:id])})
|
239
|
+
@stats = @queue.stats
|
240
|
+
|
241
|
+
end
|
242
|
+
it "should count a single completion" do
|
243
|
+
@ac["completecount"].should eq 1
|
244
|
+
|
245
|
+
end
|
246
|
+
it "should report zero for uncompleted items" do
|
247
|
+
@bc["completecount"].should eq 0
|
248
|
+
end
|
249
|
+
it "should count a single completion" do
|
250
|
+
@cc["completecount"].should eq 3
|
251
|
+
end
|
252
|
+
it "should report stats correctly" do
|
253
|
+
@stats[:redundantcompletes].should == 2
|
254
|
+
end
|
255
|
+
end
|
219
256
|
|
220
257
|
describe "Stats" do
|
221
258
|
before(:all) do
|
222
|
-
@queue.flush!
|
223
259
|
@a = insert_and_inspect("a")
|
224
260
|
|
225
261
|
@b = insert_and_inspect("b")
|
@@ -250,6 +286,9 @@ describe Mongo::Dequeue do
|
|
250
286
|
it "should count locked" do
|
251
287
|
@stats[:locked].should == 1
|
252
288
|
end
|
289
|
+
it "should count redundant completes" do
|
290
|
+
@stats[:redundantcompletes].should == 0
|
291
|
+
end
|
253
292
|
|
254
293
|
|
255
294
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: mongo-dequeue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- TelegramSam
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-19 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- pkg/mongo-dequeue-0.1.0.gem
|
101
101
|
- pkg/mongo-dequeue-0.2.0.gem
|
102
102
|
- pkg/mongo-dequeue-0.2.1.gem
|
103
|
+
- pkg/mongo-dequeue-0.3.0.gem
|
103
104
|
- spec/mongo_dequeue_spec.rb
|
104
105
|
- spec/spec_helper.rb
|
105
106
|
has_rdoc: true
|
@@ -116,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
117
|
requirements:
|
117
118
|
- - ">="
|
118
119
|
- !ruby/object:Gem::Version
|
119
|
-
hash:
|
120
|
+
hash: 838743989806676157
|
120
121
|
segments:
|
121
122
|
- 0
|
122
123
|
version: "0"
|