mongo-dequeue 0.1.0 → 0.2.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/README.rdoc CHANGED
@@ -14,19 +14,17 @@ Heavily inspired by Mongo::Queue https://github.com/skiz/mongo_queue
14
14
  == Examples
15
15
 
16
16
  === Setting up a queue
17
- Mongo::Dequeue requires a Mongo::Connection to your Mongo Server, and allows you to configure the database,
18
- collection, and the default read timeout of items in your queue. Items popped from the queue must be confirmed
19
- complete, or they will be reissued after the timeout specified.
17
+ Mongo::Dequeue requires a Mongo::Collection, and allows you to configure the default read timeout of items in your queue.
18
+ Items popped from the queue must be confirmed complete, or they will be reissued after the timeout specified.
20
19
 
21
- db = Mongo::Connection.new
20
+ mc = Mongo::Connection.new
21
+ collection = mc.db("whateverdb").collection("my_queue")
22
22
 
23
23
  options = {
24
- :database => 'whateverdb',
25
- :collection => 'my_queue',
26
24
  :timeout => 60
27
25
  }
28
26
 
29
- queue = Mongo::Dequeue.new(db, options)
27
+ queue = Mongo::Dequeue.new(collection, options)
30
28
 
31
29
  === Pushing Items
32
30
  Items have a body, passed as the first argument to push(). A body can be a string, number, hash, or array. These
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/mongo-dequeue.rb CHANGED
@@ -5,11 +5,9 @@ require 'mongo'
5
5
  # heavily inspired by https://github.com/skiz/mongo_queue
6
6
 
7
7
  class Mongo::Dequeue
8
- attr_reader :connection, :config
8
+ attr_reader :collection, :config
9
9
 
10
10
  DEFAULT_CONFIG = {
11
- :database => 'mongo_dequeue',
12
- :collection => 'mongo_dequeue',
13
11
  :timeout => 300,
14
12
  :default_priority => 3
15
13
  }.freeze
@@ -22,8 +20,8 @@ class Mongo::Dequeue
22
20
  # config = {:timeout => 90, :attempts => 2}
23
21
  # queue = Mongo::Queue.new(db, config)
24
22
  #
25
- def initialize(connection, opts={})
26
- @connection = connection
23
+ def initialize(collection, opts={})
24
+ @collection = collection
27
25
  @config = DEFAULT_CONFIG.merge(opts)
28
26
  end
29
27
 
@@ -49,7 +47,7 @@ class Mongo::Dequeue
49
47
  :body => body,
50
48
  :inserted_at => Time.now.utc,
51
49
  :complete => false,
52
- :locked_at => nil,
50
+ :locked_till => nil,
53
51
  :completed_at => nil,
54
52
  :priority => item_opts[:priority] || @config[:default_priority],
55
53
  :duplicate_key => dup_key
@@ -71,7 +69,7 @@ class Mongo::Dequeue
71
69
  begin
72
70
  timeout = opts[:timeout] || @config[:timeout]
73
71
  cmd = BSON::OrderedHash.new
74
- cmd['findandmodify'] = @config[:collection]
72
+ cmd['findandmodify'] = collection.name
75
73
  cmd['update'] = {'$set' => {:locked_till => Time.now.utc+timeout}}
76
74
  cmd['query'] = {:complete => false, '$or'=>[{:locked_till=> nil},{:locked_till=>{'$lt'=>Time.now.utc}}] }
77
75
  cmd['sort'] = {:priority=>-1,:inserted_at=>1}
@@ -92,7 +90,7 @@ class Mongo::Dequeue
92
90
  # You must provide the process identifier that the document was locked with to complete it.
93
91
  def complete(id)
94
92
  cmd = BSON::OrderedHash.new
95
- cmd['findandmodify'] = @config[:collection]
93
+ cmd['findandmodify'] = collection.name
96
94
  cmd['query'] = {:_id => BSON::ObjectId.from_string(id), :complete => false}
97
95
  cmd['update'] = {:completed_at => Time.now.utc, :complete => true}
98
96
  cmd['limit'] = 1
@@ -113,10 +111,10 @@ class Mongo::Dequeue
113
111
  return db.eval(
114
112
  function(){
115
113
  var nowutc = new Date();
116
- var a = db.#{config[:collection]}.count({'complete': false, '$or':[{'locked_till':null},{'locked_till':{'$lt':nowutc}}] });
117
- var c = db.#{config[:collection]}.count({'complete': true});
118
- var t = db.#{config[:collection]}.count();
119
- var l = db.#{config[:collection]}.count({'complete': false, 'locked_till': {'$gte':nowutc} });
114
+ var a = db.#{collection.name}.count({'complete': false, '$or':[{'locked_till':null},{'locked_till':{'$lt':nowutc}}] });
115
+ var c = db.#{collection.name}.count({'complete': true});
116
+ var t = db.#{collection.name}.count();
117
+ var l = db.#{collection.name}.count({'complete': false, 'locked_till': {'$gte':nowutc} });
120
118
  return [a, c, t, l];
121
119
  }
122
120
  );
@@ -142,8 +140,5 @@ class Mongo::Dequeue
142
140
  result['okay'] == 0 ? nil : result['value']
143
141
  end
144
142
 
145
- def collection #:nodoc:
146
- @connection.db(@config[:database]).collection(@config[:collection])
147
- end
148
143
 
149
144
  end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mongo-dequeue}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["TelegramSam"]
12
+ s.date = %q{2011-06-30}
13
+ s.description = %q{A de-duplicating priority queue that uses mongodb as the storage engine.}
14
+ s.email = %q{telegramsam@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/mongo-dequeue.rb",
27
+ "mongo-dequeue.gemspec",
28
+ "pkg/mongo-dequeue-0.1.0.gem",
29
+ "spec/mongo_dequeue_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/TelegramSam/Dequeue}
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.5.3}
36
+ s.summary = %q{Mongo based de-duplicating pritority queue}
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<json>, [">= 0"])
43
+ s.add_runtime_dependency(%q<mongo>, [">= 0"])
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<json>, [">= 0"])
50
+ s.add_dependency(%q<mongo>, [">= 0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ s.add_dependency(%q<mongo>, [">= 0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
Binary file
@@ -11,11 +11,9 @@ describe Mongo::Dequeue do
11
11
 
12
12
  before(:all) do
13
13
  opts = {
14
- :database => 'mongo_queue_spec',
15
- :collection => 'spec',
16
14
  :timeout => 60}
17
- @db = Mongo::Connection.new('localhost', nil, :pool_size => 4)
18
- @queue = Mongo::Dequeue.new(@db, opts)
15
+ @collection = Mongo::Connection.new('localhost', nil, :pool_size => 4).db('mongo_queue_spec').collection('spec')
16
+ @queue = Mongo::Dequeue.new(@collection, opts)
19
17
  end
20
18
 
21
19
  before(:each) do
@@ -25,15 +23,7 @@ describe Mongo::Dequeue do
25
23
  describe "Configuration" do
26
24
 
27
25
  it "should set the connection" do
28
- @queue.connection.should be(@db)
29
- end
30
-
31
- it "should allow database option" do
32
- @queue.config[:database].should eql('mongo_queue_spec')
33
- end
34
-
35
- it "should allow collection option" do
36
- @queue.config[:collection].should eql('spec')
26
+ @queue.collection.should be(@collection)
37
27
  end
38
28
 
39
29
  it "should allow timeout option" do
@@ -42,7 +32,6 @@ describe Mongo::Dequeue do
42
32
 
43
33
  it "should have a sane set of defaults" do
44
34
  q = Mongo::Dequeue.new(nil)
45
- q.config[:collection].should eql 'mongo_dequeue'
46
35
  q.config[:timeout].should eql 300
47
36
  end
48
37
  end
@@ -162,7 +151,7 @@ describe Mongo::Dequeue do
162
151
  a = insert_and_inspect("foo")
163
152
  m = @queue.pop
164
153
  m[:body].should eq "foo"
165
- @queue.send(:collection).count.should be 1
154
+ @queue.send(:collection).count.should be 1
166
155
  end
167
156
 
168
157
  it "should return an id" 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.1.0
5
+ version: 0.2.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-06-29 00:00:00 -06:00
13
+ date: 2011-06-30 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -96,6 +96,8 @@ files:
96
96
  - Rakefile
97
97
  - VERSION
98
98
  - lib/mongo-dequeue.rb
99
+ - mongo-dequeue.gemspec
100
+ - pkg/mongo-dequeue-0.1.0.gem
99
101
  - spec/mongo_dequeue_spec.rb
100
102
  - spec/spec_helper.rb
101
103
  has_rdoc: true
@@ -112,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  requirements:
113
115
  - - ">="
114
116
  - !ruby/object:Gem::Version
115
- hash: 4221506242229050956
117
+ hash: -2750562918096667173
116
118
  segments:
117
119
  - 0
118
120
  version: "0"