mongo-dequeue 0.2.1 → 0.3.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 +21 -7
- data/mongo-dequeue.gemspec +3 -2
- data/pkg/mongo-dequeue-0.2.1.gem +0 -0
- data/spec/mongo_dequeue_spec.rb +13 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/mongo-dequeue.rb
CHANGED
@@ -85,16 +85,20 @@ class Mongo::Dequeue
|
|
85
85
|
}
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
88
|
# Remove the document from the queue. This should be called when the work is done and the document is no longer needed.
|
90
89
|
# You must provide the process identifier that the document was locked with to complete it.
|
91
90
|
def complete(id)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
91
|
+
begin
|
92
|
+
cmd = BSON::OrderedHash.new
|
93
|
+
cmd['findandmodify'] = collection.name
|
94
|
+
cmd['query'] = {:_id => BSON::ObjectId.from_string(id), :complete => false}
|
95
|
+
cmd['update'] = {'$set' => {:completed_at => Time.now.utc, :complete => true} }
|
96
|
+
cmd['limit'] = 1
|
97
|
+
collection.db.command(cmd)
|
98
|
+
rescue Mongo::OperationFailure => of
|
99
|
+
#opfailure happens when item has been already completed
|
100
|
+
return nil
|
101
|
+
end
|
98
102
|
end
|
99
103
|
|
100
104
|
# Removes completed job history
|
@@ -133,6 +137,16 @@ class Mongo::Dequeue
|
|
133
137
|
return Digest::MD5.hexdigest(body.to_json) #won't ever match a duplicate. Need a better way to handle hashes and arrays.
|
134
138
|
end
|
135
139
|
|
140
|
+
def peek
|
141
|
+
firstfew = collection.find({
|
142
|
+
:complete => false,
|
143
|
+
'$or'=>[{:locked_till=> nil},{:locked_till=>{'$lt'=>Time.now.utc}}]
|
144
|
+
},
|
145
|
+
:sort => [[:priority, :descending],[:inserted_at, :ascending]],
|
146
|
+
:limit => 10)
|
147
|
+
return firstfew
|
148
|
+
end
|
149
|
+
|
136
150
|
|
137
151
|
protected
|
138
152
|
|
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.3.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-11}
|
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 = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"mongo-dequeue.gemspec",
|
28
28
|
"pkg/mongo-dequeue-0.1.0.gem",
|
29
29
|
"pkg/mongo-dequeue-0.2.0.gem",
|
30
|
+
"pkg/mongo-dequeue-0.2.1.gem",
|
30
31
|
"spec/mongo_dequeue_spec.rb",
|
31
32
|
"spec/spec_helper.rb"
|
32
33
|
]
|
Binary file
|
data/spec/mongo_dequeue_spec.rb
CHANGED
@@ -203,6 +203,19 @@ describe Mongo::Dequeue do
|
|
203
203
|
end
|
204
204
|
|
205
205
|
end
|
206
|
+
|
207
|
+
describe "Peek" do
|
208
|
+
it "should peek properly" do
|
209
|
+
@a = insert_and_inspect("a")
|
210
|
+
@b = insert_and_inspect("b")
|
211
|
+
|
212
|
+
@peek = []
|
213
|
+
p = @queue.peek
|
214
|
+
p.each{|q| @peek << q }
|
215
|
+
|
216
|
+
@peek.length.should == 2
|
217
|
+
end
|
218
|
+
end
|
206
219
|
|
207
220
|
describe "Stats" do
|
208
221
|
before(:all) do
|
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.3.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-11 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- mongo-dequeue.gemspec
|
100
100
|
- pkg/mongo-dequeue-0.1.0.gem
|
101
101
|
- pkg/mongo-dequeue-0.2.0.gem
|
102
|
+
- pkg/mongo-dequeue-0.2.1.gem
|
102
103
|
- spec/mongo_dequeue_spec.rb
|
103
104
|
- spec/spec_helper.rb
|
104
105
|
has_rdoc: true
|
@@ -115,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
116
|
requirements:
|
116
117
|
- - ">="
|
117
118
|
- !ruby/object:Gem::Version
|
118
|
-
hash: -
|
119
|
+
hash: -1516401480189970073
|
119
120
|
segments:
|
120
121
|
- 0
|
121
122
|
version: "0"
|