hotseat 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Add work queue functionality to an existing CouchDB database.
4
4
 
5
+ `gem install hotseat`
6
+
5
7
  == Contributing to Hotseat
6
8
 
7
9
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/hotseat.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hotseat}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Elad Kehat"]
12
- s.date = %q{2011-08-17}
12
+ s.date = %q{2011-08-20}
13
13
  s.email = %q{eladkehat@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -2,18 +2,18 @@ module Hotseat
2
2
 
3
3
  class << self
4
4
 
5
- def queue(db)
6
- Hotseat::Queue.new(db)
5
+ def queue(db, options={})
6
+ Hotseat::Queue.new(db, options)
7
7
  end
8
8
  alias :make_queue :queue
9
9
 
10
- def queue?(db)
10
+ def queue?(db, design_doc_name = Hotseat::Queue::DEFAULT_CONFIG[:design_doc_name])
11
11
  # ignore system dbs like _replicator and _users
12
12
  return false if db.name =~ /^_/
13
13
  begin
14
- db.get design_doc_id
14
+ db.get "_design/#{design_doc_name}"
15
15
  rescue RestClient::ResourceNotFound
16
- # either the database or the design doc does not exist
16
+ # either the database or the design doc does not exist
17
17
  false
18
18
  end
19
19
  end
@@ -24,66 +24,6 @@ module Hotseat
24
24
  end
25
25
  end
26
26
 
27
- def design_doc_id
28
- "_design/#{config[:design_doc_name]}"
29
- end
30
-
31
- def pending_view_name
32
- "#{config[:design_doc_name]}/#{config[:pending_view_name]}"
33
- end
34
-
35
- def locked_view_name
36
- "#{config[:design_doc_name]}/#{config[:locked_view_name]}"
37
- end
38
-
39
- def done_view_name
40
- "#{config[:design_doc_name]}/#{config[:done_view_name]}"
41
- end
42
-
43
- def all_view_name
44
- "#{config[:design_doc_name]}/#{config[:all_view_name]}"
45
- end
46
-
47
- def design_doc
48
- q = "doc.#{config[:object_name]}"
49
- lock = "#{q}.lock"
50
- done = "#{q}.done"
51
- pending_func = <<-JAVASCRIPT
52
- function(doc) { if (#{q} && !(#{lock} || #{done})) emit(#{q}.at, null); }
53
- JAVASCRIPT
54
- locked_func = <<-JAVASCRIPT
55
- function(doc) { if (#{q} && #{lock}) emit(#{lock}.at, null); }
56
- JAVASCRIPT
57
- done_func = <<-JAVASCRIPT
58
- function(doc) { if (#{q} && #{done}) emit(#{done}.at, null); }
59
- JAVASCRIPT
60
- all_func = <<-JAVASCRIPT
61
- function(doc) { if (#{q}) emit(#{q}.at, null); }
62
- JAVASCRIPT
63
- {
64
- '_id' => "_design/#{config[:design_doc_name]}",
65
- :views => {
66
- config[:pending_view_name] => { :map => pending_func.chomp },
67
- config[:locked_view_name] => { :map => locked_func.chomp },
68
- config[:done_view_name] => { :map => done_func.chomp },
69
- config[:all_view_name] => { :map => all_func.chomp },
70
- }
71
- }
72
- end
73
-
74
- def config
75
- CONFIG
76
- end
77
-
78
27
  end
79
28
 
80
- CONFIG = {
81
- :design_doc_name => 'hotseat_queue',
82
- :pending_view_name => 'pending',
83
- :locked_view_name => 'locked',
84
- :done_view_name => 'done',
85
- :all_view_name => 'all',
86
- :object_name => 'hotseat',
87
- }
88
-
89
- end
29
+ end
data/lib/hotseat/queue.rb CHANGED
@@ -6,56 +6,109 @@ module Hotseat
6
6
  end
7
7
 
8
8
  class Queue
9
- attr_reader :db
9
+ attr_accessor :db, :config
10
+
11
+ DEFAULT_CONFIG = {
12
+ :design_doc_name => 'hotseat_queue',
13
+ :pending_view_name => 'pending',
14
+ :locked_view_name => 'locked',
15
+ :done_view_name => 'done',
16
+ :all_view_name => 'all',
17
+ :object_name => 'hotseat',
18
+ }
19
+
20
+ def initialize(db, options={})
21
+ @db = db
22
+ @config = DEFAULT_CONFIG.merge(options)
23
+ unless Hotseat.queue?(@db, @config[:design_doc_name])
24
+ @db.save_doc design_doc
25
+ end
26
+ end
10
27
 
11
- class << self
28
+ def design_doc_id
29
+ "_design/#{config[:design_doc_name]}"
30
+ end
12
31
 
13
- def patch(doc)
14
- doc[Hotseat.config[:object_name]] = {'at' => Time.now.utc.iso8601, 'by' => $$}
15
- doc
16
- end
32
+ def pending_view_name
33
+ "#{config[:design_doc_name]}/#{config[:pending_view_name]}"
34
+ end
17
35
 
18
- def unpatch(doc)
19
- doc.delete( Hotseat.config[:object_name] )
20
- doc
21
- end
36
+ def locked_view_name
37
+ "#{config[:design_doc_name]}/#{config[:locked_view_name]}"
38
+ end
22
39
 
23
- def add_lock(doc)
24
- obj = doc[Hotseat.config[:object_name]]
25
- obj['lock'] = {'at' => Time.now.utc.iso8601, 'by' => $$}
26
- doc
27
- end
40
+ def done_view_name
41
+ "#{config[:design_doc_name]}/#{config[:done_view_name]}"
42
+ end
28
43
 
29
- def locked?(doc)
30
- if obj = doc[Hotseat.config[:object_name]]
31
- obj.has_key? 'lock'
32
- end
33
- end
44
+ def all_view_name
45
+ "#{config[:design_doc_name]}/#{config[:all_view_name]}"
46
+ end
34
47
 
35
- def remove_lock(doc)
36
- obj = doc[Hotseat.config[:object_name]]
37
- obj.delete 'lock'
38
- doc
39
- end
48
+ def design_doc
49
+ q = "doc.#{config[:object_name]}"
50
+ lock = "#{q}.lock"
51
+ done = "#{q}.done"
52
+ pending_func = <<-JAVASCRIPT
53
+ function(doc) { if (#{q} && !(#{lock} || #{done})) emit(#{q}.at, null); }
54
+ JAVASCRIPT
55
+ locked_func = <<-JAVASCRIPT
56
+ function(doc) { if (#{q} && #{lock}) emit(#{lock}.at, null); }
57
+ JAVASCRIPT
58
+ done_func = <<-JAVASCRIPT
59
+ function(doc) { if (#{q} && #{done}) emit(#{done}.at, null); }
60
+ JAVASCRIPT
61
+ all_func = <<-JAVASCRIPT
62
+ function(doc) { if (#{q}) emit(#{q}.at, null); }
63
+ JAVASCRIPT
64
+ {
65
+ '_id' => "_design/#{config[:design_doc_name]}",
66
+ :views => {
67
+ config[:pending_view_name] => { :map => pending_func.strip },
68
+ config[:locked_view_name] => { :map => locked_func.strip },
69
+ config[:done_view_name] => { :map => done_func.strip },
70
+ config[:all_view_name] => { :map => all_func.strip },
71
+ }
72
+ }
73
+ end
40
74
 
41
- def mark_done(doc)
42
- obj = doc[Hotseat.config[:object_name]]
43
- obj['done'] = {'at' => Time.now.utc.iso8601, 'by' => $$}
44
- doc
45
- end
75
+ def patch(doc)
76
+ doc[config[:object_name]] = {'at' => Time.now.utc.iso8601, 'by' => $$}
77
+ doc
78
+ end
46
79
 
80
+ def unpatch(doc)
81
+ doc.delete( config[:object_name] )
82
+ doc
47
83
  end
48
84
 
49
- def initialize(db)
50
- @db = db
51
- unless Hotseat.queue?(@db)
52
- @db.save_doc Hotseat.design_doc
85
+ def add_lock(doc)
86
+ obj = doc[config[:object_name]]
87
+ obj['lock'] = {'at' => Time.now.utc.iso8601, 'by' => $$}
88
+ doc
89
+ end
90
+
91
+ def locked?(doc)
92
+ if obj = doc[config[:object_name]]
93
+ obj.has_key? 'lock'
53
94
  end
54
95
  end
55
96
 
97
+ def remove_lock(doc)
98
+ obj = doc[config[:object_name]]
99
+ obj.delete 'lock'
100
+ doc
101
+ end
102
+
103
+ def mark_done(doc)
104
+ obj = doc[config[:object_name]]
105
+ obj['done'] = {'at' => Time.now.utc.iso8601, 'by' => $$}
106
+ doc
107
+ end
108
+
56
109
  def add(doc_id)
57
110
  @db.update_doc(doc_id) do |doc|
58
- Queue.patch doc
111
+ patch doc
59
112
  yield doc if block_given?
60
113
  end
61
114
  end
@@ -63,23 +116,23 @@ module Hotseat
63
116
  def add_bulk(doc_ids)
64
117
  #Note: this silently ignores missing doc_ids
65
118
  docs = @db.bulk_load(doc_ids)['rows'].map{|row| row['doc']}.compact
66
- docs.each {|doc| Queue.patch doc }
119
+ docs.each {|doc| patch doc }
67
120
  @db.bulk_save docs, use_uuids=false
68
121
  end
69
122
 
70
123
  def num_pending
71
- @db.view(Hotseat.pending_view_name, :limit => 0)['total_rows']
124
+ @db.view(pending_view_name, :limit => 0)['total_rows']
72
125
  end
73
126
  alias :size :num_pending
74
127
 
75
128
  def get(n=1)
76
- rows = @db.view(Hotseat.pending_view_name, :limit => n, :include_docs => true)['rows']
129
+ rows = @db.view(pending_view_name, :limit => n, :include_docs => true)['rows']
77
130
  rows.map{|row| row['doc']} unless rows.empty?
78
131
  end
79
132
 
80
133
  def lease(n=1)
81
134
  if docs = get(n)
82
- docs.each {|doc| Queue.add_lock doc }
135
+ docs.each {|doc| add_lock doc }
83
136
  response = @db.bulk_save docs, use_uuids=false
84
137
  # Some docs may have failed to lock - probably updated by another process
85
138
  locked_ids = response.reject{|res| res['error']}.map{|res| res['id']}
@@ -93,16 +146,16 @@ module Hotseat
93
146
  end
94
147
 
95
148
  def num_locked
96
- @db.view(Hotseat.locked_view_name, :limit => 0)['total_rows']
149
+ @db.view(locked_view_name, :limit => 0)['total_rows']
97
150
  end
98
151
 
99
152
  def remove(doc_id, opts={})
100
153
  @db.update_doc(doc_id) do |doc|
101
- raise(QueueError, "Document was already removed") unless Queue.locked?(doc)
154
+ raise(QueueError, "Document was already removed") unless locked?(doc)
102
155
  if opts.delete(:forget)
103
- Queue.unpatch doc
156
+ unpatch doc
104
157
  else
105
- Queue.mark_done( Queue.remove_lock( doc ) )
158
+ mark_done( remove_lock( doc ) )
106
159
  end
107
160
  yield doc if block_given?
108
161
  end
@@ -112,13 +165,13 @@ module Hotseat
112
165
  rows = @db.bulk_load(doc_ids)['rows']
113
166
  docs, missing = rows.partition {|row| row['doc'] }
114
167
  docs.map! {|row| row['doc'] }
115
- locked, unlocked = docs.partition {|doc| Queue.locked? doc }
168
+ locked, unlocked = docs.partition {|doc| locked? doc }
116
169
  forget = opts.delete(:forget)
117
170
  locked.each do |doc|
118
171
  if forget
119
- Queue.unpatch doc
172
+ unpatch doc
120
173
  else
121
- Queue.mark_done( Queue.remove_lock( doc ) )
174
+ mark_done( remove_lock( doc ) )
122
175
  end
123
176
  end
124
177
  @db.bulk_save locked, use_uuids=false
@@ -129,31 +182,31 @@ module Hotseat
129
182
  end
130
183
 
131
184
  def num_done
132
- @db.view(Hotseat.done_view_name, :limit => 0)['total_rows']
185
+ @db.view(done_view_name, :limit => 0)['total_rows']
133
186
  end
134
187
 
135
188
  def num_all
136
- @db.view(Hotseat.all_view_name, :limit => 0)['total_rows']
189
+ @db.view(all_view_name, :limit => 0)['total_rows']
137
190
  end
138
191
  alias :num_total :num_all
139
192
 
140
193
  def forget(doc_id)
141
194
  @db.update_doc(doc_id) do |doc|
142
- Queue.unpatch doc
195
+ unpatch doc
143
196
  end
144
197
  end
145
198
 
146
199
  def forget_bulk(doc_ids)
147
200
  #Note: this silently ignores missing doc_ids
148
201
  docs = @db.bulk_load(doc_ids)['rows'].map{|row| row['doc']}.compact
149
- docs.each {|doc| Queue.unpatch doc }
202
+ docs.each {|doc| unpatch doc }
150
203
  @db.bulk_save docs, use_uuids=false
151
204
  end
152
205
 
153
206
  def purge
154
- rows = @db.view(Hotseat.all_view_name, :include_docs => true)['rows']
207
+ rows = @db.view(all_view_name, :include_docs => true)['rows']
155
208
  docs = rows.map{|row| row['doc']}
156
- docs.each{|doc| Queue.unpatch doc }
209
+ docs.each{|doc| unpatch doc }
157
210
  @db.bulk_save docs, use_uuids=false
158
211
  end
159
212
 
@@ -28,19 +28,23 @@ module Hotseat
28
28
  it "should create a Hotseat design doc in the database if one does not exist" do
29
29
  reset_test_db!
30
30
  q = Hotseat::Queue.new(DB)
31
- q.db.get(Hotseat.design_doc_id).should_not be_nil
31
+ q.db.get(q.design_doc_id).should_not be_nil
32
32
  end
33
33
  end
34
34
 
35
35
  describe "#patch" do
36
+ before(:each) do
37
+ reset_test_queue!
38
+ end
39
+
36
40
  it "should add a queue object on a document" do
37
41
  doc = sample_doc
38
- Queue.patch doc
39
- doc.should have_key(Hotseat.config[:object_name])
42
+ @q.patch doc
43
+ doc.should have_key(@q.config[:object_name])
40
44
  end
41
45
 
42
46
  it "should return the patched document with original data intact" do
43
- doc = Queue.patch sample_doc
47
+ doc = @q.patch sample_doc
44
48
  sample_doc.each do |k,v|
45
49
  doc[k].should == v
46
50
  end
@@ -49,52 +53,63 @@ module Hotseat
49
53
 
50
54
  describe "#unpatch" do
51
55
  it "should remove the queue object from a document" do
52
- doc = Queue.unpatch( Queue.patch( sample_doc ) )
53
- doc.should_not have_key(Hotseat.config[:object_name])
56
+ reset_test_queue!
57
+ doc = @q.unpatch( @q.patch( sample_doc ) )
58
+ doc.should_not have_key(@q.config[:object_name])
54
59
  end
55
60
  end
56
61
 
57
62
  describe "#add_lock" do
58
63
  it "should add a lock object on a patched document" do
59
- doc = Queue.add_lock( Queue.patch( sample_doc ) )
60
- patch = doc[Hotseat.config[:object_name]]
64
+ reset_test_queue!
65
+ doc = @q.add_lock( @q.patch( sample_doc ) )
66
+ patch = doc[@q.config[:object_name]]
61
67
  patch.should have_key('lock')
62
68
  end
63
69
  end
64
70
 
65
71
  describe "#remove_lock" do
66
- before(:each) { @doc = Queue.remove_lock( Queue.add_lock( Queue.patch( sample_doc ) ) ) }
72
+ before(:each) do
73
+ reset_test_queue!
74
+ @doc = @q.remove_lock( @q.add_lock( @q.patch( sample_doc ) ) )
75
+ end
67
76
  it "should remove a lock object added by #add_lock" do
68
- patch = @doc[Hotseat.config[:object_name]]
77
+ patch = @doc[@q.config[:object_name]]
69
78
  patch.should_not have_key('lock')
70
79
  end
71
80
  it "should leave the queue patch intact" do
72
- @doc.should have_key(Hotseat.config[:object_name])
81
+ @doc.should have_key(@q.config[:object_name])
73
82
  end
74
83
  end
75
84
 
76
85
  describe "#locked?" do
86
+ before(:each) do
87
+ reset_test_queue!
88
+ end
77
89
  it "should be true for a locked document" do
78
- doc = Queue.add_lock( Queue.patch( sample_doc ) )
79
- Queue.locked?(doc).should be_true
90
+ doc = @q.add_lock( @q.patch( sample_doc ) )
91
+ @q.locked?(doc).should be_true
80
92
  end
81
93
  it "should be false for a patched, but not locked document" do
82
- doc = Queue.patch( sample_doc )
83
- Queue.locked?(doc).should be_false
94
+ doc = @q.patch( sample_doc )
95
+ @q.locked?(doc).should be_false
84
96
  end
85
97
  it "should be false for an unlocked document" do
86
- doc = Queue.remove_lock( Queue.add_lock( Queue.patch( sample_doc ) ) )
87
- Queue.locked?(doc).should be_false
98
+ doc = @q.remove_lock( @q.add_lock( @q.patch( sample_doc ) ) )
99
+ @q.locked?(doc).should be_false
88
100
  end
89
101
  end
90
102
 
91
103
  describe "#mark_done" do
92
- before(:each) { @doc = Queue.mark_done( Queue.patch( sample_doc ) ) }
104
+ before(:each) do
105
+ reset_test_queue!
106
+ @doc = @q.mark_done( @q.patch( sample_doc ) )
107
+ end
93
108
  it "should leave the queue patch intact" do
94
- @doc.should have_key(Hotseat.config[:object_name])
109
+ @doc.should have_key(@q.config[:object_name])
95
110
  end
96
111
  it "should add a 'done' object on a patched document" do
97
- patch = @doc[Hotseat.config[:object_name]]
112
+ patch = @doc[@q.config[:object_name]]
98
113
  patch.should have_key('done')
99
114
  end
100
115
  end
@@ -107,7 +122,7 @@ module Hotseat
107
122
 
108
123
  it "should add a document to the queue, given a doc id" do
109
124
  @q.add @doc_id
110
- DB.get(@doc_id).should have_key(Hotseat.config[:object_name])
125
+ DB.get(@doc_id).should have_key(@q.config[:object_name])
111
126
  end
112
127
 
113
128
  it "should save changes made in the block" do
@@ -127,7 +142,7 @@ module Hotseat
127
142
  doc_ids = create_some_docs
128
143
  @q.add_bulk doc_ids
129
144
  doc_ids.each do |doc_id|
130
- DB.get(doc_id).should have_key(Hotseat.config[:object_name])
145
+ DB.get(doc_id).should have_key(@q.config[:object_name])
131
146
  end
132
147
  end
133
148
  end
@@ -153,15 +168,15 @@ module Hotseat
153
168
  docs.each do |doc|
154
169
  db_doc = DB.get(doc['_id'])
155
170
  db_doc.should be_kind_of CouchRest::Document
156
- db_doc.should have_key(Hotseat.config[:object_name])
171
+ db_doc.should have_key(@q.config[:object_name])
157
172
  end
158
173
  end
159
174
 
160
175
  it "should lock a pending document" do
161
176
  doc_id = @q.lease.first['_id']
162
177
  doc = DB.get(doc_id)
163
- doc.should have_key(Hotseat.config[:object_name])
164
- doc[Hotseat.config[:object_name]].should have_key('lock')
178
+ doc.should have_key(@q.config[:object_name])
179
+ doc[@q.config[:object_name]].should have_key('lock')
165
180
  end
166
181
 
167
182
  it "should lock and return up to the specified number of documents" do
@@ -194,7 +209,7 @@ module Hotseat
194
209
 
195
210
  it "should not be pending" do
196
211
  locked_id = @q.lease.first['_id']
197
- pending_ids = @q.db.view(Hotseat.pending_view_name)['rows'].map{|row| row['id']}
212
+ pending_ids = @q.db.view(@q.pending_view_name)['rows'].map{|row| row['id']}
198
213
  pending_ids.should_not include(locked_id)
199
214
  end
200
215
 
@@ -216,15 +231,15 @@ module Hotseat
216
231
  docs.should have(2).items
217
232
  docs.each do |doc|
218
233
  db_doc = DB.get(doc['_id'])
219
- db_doc.should have_key(Hotseat.config[:object_name])
234
+ db_doc.should have_key(@q.config[:object_name])
220
235
  end
221
236
  end
222
237
 
223
238
  it "should not lock the documents it returns" do
224
239
  doc_id = @q.get.first['_id']
225
240
  doc = DB.get(doc_id)
226
- doc.should have_key(Hotseat.config[:object_name])
227
- doc[Hotseat.config[:object_name]].should_not have_key('lock')
241
+ doc.should have_key(@q.config[:object_name])
242
+ doc[@q.config[:object_name]].should_not have_key('lock')
228
243
  end
229
244
 
230
245
  it "should return up to the specified number of documents" do
@@ -244,8 +259,8 @@ module Hotseat
244
259
  it "should unlock a leased document" do
245
260
  @q.remove @doc_id
246
261
  doc = DB.get(@doc_id)
247
- doc.should have_key(Hotseat.config[:object_name])
248
- doc[Hotseat.config[:object_name]].should_not have_key('lock')
262
+ doc.should have_key(@q.config[:object_name])
263
+ doc[@q.config[:object_name]].should_not have_key('lock')
249
264
  end
250
265
 
251
266
  it "should remove a document from the queue" do
@@ -274,14 +289,14 @@ module Hotseat
274
289
  it "should leave queue history in the document (mark as done) by default" do
275
290
  @q.remove @doc_id
276
291
  doc = DB.get(@doc_id)
277
- doc.should have_key(Hotseat.config[:object_name])
278
- doc[Hotseat.config[:object_name]].should have_key('done')
292
+ doc.should have_key(@q.config[:object_name])
293
+ doc[@q.config[:object_name]].should have_key('done')
279
294
  end
280
295
 
281
296
  it "should delete queue history from the document when forget=true" do
282
297
  @q.remove @doc_id, :forget => true
283
298
  doc = DB.get(@doc_id)
284
- doc.should_not have_key(Hotseat.config[:object_name])
299
+ doc.should_not have_key(@q.config[:object_name])
285
300
  end
286
301
 
287
302
  it "should save any changes made in the block" do
@@ -307,8 +322,8 @@ module Hotseat
307
322
  @q.remove_bulk @doc_ids
308
323
  docs = DB.get_bulk(@doc_ids)['rows'].map{|row| row['doc']}
309
324
  docs.each do |doc|
310
- doc.should have_key(Hotseat.config[:object_name])
311
- doc[Hotseat.config[:object_name]].should_not have_key('lock')
325
+ doc.should have_key(@q.config[:object_name])
326
+ doc[@q.config[:object_name]].should_not have_key('lock')
312
327
  end
313
328
  end
314
329
 
@@ -340,8 +355,8 @@ module Hotseat
340
355
  @q.remove_bulk @doc_ids
341
356
  docs = DB.get_bulk(@doc_ids)['rows'].map{|row| row['doc']}
342
357
  docs.each do |doc|
343
- doc.should have_key(Hotseat.config[:object_name])
344
- doc[Hotseat.config[:object_name]].should have_key('done')
358
+ doc.should have_key(@q.config[:object_name])
359
+ doc[@q.config[:object_name]].should have_key('done')
345
360
  end
346
361
  end
347
362
 
@@ -349,7 +364,7 @@ module Hotseat
349
364
  @q.remove_bulk @doc_ids, :forget => true
350
365
  docs = DB.get_bulk(@doc_ids)['rows'].map{|row| row['doc']}
351
366
  docs.each do |doc|
352
- doc.should_not have_key(Hotseat.config[:object_name])
367
+ doc.should_not have_key(@q.config[:object_name])
353
368
  end
354
369
  end
355
370
  end
@@ -383,7 +398,7 @@ module Hotseat
383
398
  doc_id = @q.get.first['_id']
384
399
  @q.forget doc_id
385
400
  doc = DB.get(doc_id)
386
- doc.should_not have_key(Hotseat.config[:object_name])
401
+ doc.should_not have_key(@q.config[:object_name])
387
402
  end
388
403
  end
389
404
 
@@ -394,7 +409,7 @@ module Hotseat
394
409
  doc_ids = @q.get(3).map{|doc| doc['_id'] }
395
410
  @q.forget_bulk doc_ids
396
411
  @q.db.bulk_load(doc_ids)['rows'].map{|row| row['doc']}.each do |doc|
397
- doc.should_not have_key(Hotseat.config[:object_name])
412
+ doc.should_not have_key(@q.config[:object_name])
398
413
  end
399
414
  end
400
415
  end
@@ -412,6 +427,33 @@ module Hotseat
412
427
  @q.num_all.should == 0
413
428
  end
414
429
  end
415
- end
416
430
 
431
+ context "when two queues are defined on the same DB" do
432
+ before do
433
+ reset_test_db!
434
+ @doc_ids = create_some_docs(10)
435
+ @q1 = Hotseat.make_queue(DB, :design_doc_name => 'hotseat1_queue', :object_name => 'hotseat1')
436
+ @q2 = Hotseat.make_queue(DB, :design_doc_name => 'hotseat2_queue', :object_name => 'hotseat2')
437
+ end
438
+
439
+ it "#add should add a doc to the specified queue only" do
440
+ @q1.add @doc_ids[0]
441
+ @q2.add @doc_ids[1]
442
+ DB.get(@doc_ids[0]).should have_key(@q1.config[:object_name])
443
+ DB.get(@doc_ids[0]).should_not have_key(@q2.config[:object_name])
444
+ DB.get(@doc_ids[1]).should have_key(@q2.config[:object_name])
445
+ DB.get(@doc_ids[1]).should_not have_key(@q1.config[:object_name])
446
+ end
447
+
448
+ it "#lease should lease docs from the specified queue" do
449
+ @q1.add_bulk @doc_ids[0, 5]
450
+ @q2.add_bulk @doc_ids[5, 5]
451
+ doc1 = @q1.lease.first
452
+ @doc_ids[0, 5].should include(doc1['_id'])
453
+ @q2.lease(3).each do |doc|
454
+ @doc_ids[5, 5].should include(doc['_id'])
455
+ end
456
+ end
457
+ end
458
+ end
417
459
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotseat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-08-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: couchrest
16
- requirement: &75234680 !ruby/object:Gem::Requirement
16
+ requirement: &75495540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75234680
24
+ version_requirements: *75495540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &75234410 !ruby/object:Gem::Requirement
27
+ requirement: &75494710 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *75234410
35
+ version_requirements: *75494710
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &75234140 !ruby/object:Gem::Requirement
38
+ requirement: &75493850 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *75234140
46
+ version_requirements: *75493850
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &75233890 !ruby/object:Gem::Requirement
49
+ requirement: &75467480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *75233890
57
+ version_requirements: *75467480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &75233580 !ruby/object:Gem::Requirement
60
+ requirement: &75466850 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *75233580
68
+ version_requirements: *75466850
69
69
  description:
70
70
  email: eladkehat@gmail.com
71
71
  executables: []
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  segments:
105
105
  - 0
106
- hash: 620751953
106
+ hash: -513056433
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements: