coordinator 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57e51cb508420441045a2d7953063aa80731ff9a
4
- data.tar.gz: e968db6fa6a80e0e140d8020cdaa572a46c672e5
3
+ metadata.gz: ba122b99d0854436ad66722efd17fb50dc1a4d27
4
+ data.tar.gz: a65bc1f944b110a655a4895ade5f7ec283d2c6f7
5
5
  SHA512:
6
- metadata.gz: f3841dab5c0ba4721b3706e899bb217266c70eea15a867d382bf38bda6e4b57e0c9d3532e18bad03902e66b1f25e598ab3d780fd2981e7838bffede316276815
7
- data.tar.gz: a57895e4b8291722d69d83fcaec07c7d350f74014cea58eb372eeefb35d4f2509e8d16d85703aca56f7b5ee59ceb2e135ec5dcc6e239f749ca6134bff625dd36
6
+ metadata.gz: c229709dd74c66705eec7350e0e6fe712e43e037e0e42179bd605dc1cd660b4427beda31aa493f21ffb2346d98c51a1e46697d12eda8988e5dc4314272368983
7
+ data.tar.gz: 20da3611c6041f5622f69e29fe22917f4ae461afd866ffd71d89357a8de4b65a0ac7547e9fbe839a8290747e19119d5e105a5ed62977d8a79501c3aea62dc842
data/README.md CHANGED
@@ -33,6 +33,9 @@ Or install it yourself as:
33
33
  @coordinator.add_task("medium", 2)
34
34
  @coordinator.add_priority_task("high", 3)
35
35
 
36
+ @coordinator.length_all # returns 3
37
+ @coordinator.peek_all # returns [3, 2]
38
+
36
39
  @coordinator.next_task(["high"]) # returns 3
37
40
  @coordinator.next_task(["medium"]) # returns 2
38
41
 
@@ -38,6 +38,14 @@ module Coordinator
38
38
  }
39
39
  end
40
40
 
41
+ def length_all
42
+ @queues.inject(0) { |sum, queue| sum + queue.length }
43
+ end
44
+
45
+ def peek_all
46
+ @queues.map(&:peek).compact
47
+ end
48
+
41
49
  private
42
50
 
43
51
  def queue_for_skill(skill)
@@ -42,6 +42,8 @@ module Coordinator
42
42
  @skill
43
43
  end
44
44
 
45
+ # store delegation methods
46
+
45
47
  def items
46
48
  @store.items
47
49
  end
@@ -53,5 +55,9 @@ module Coordinator
53
55
  def length
54
56
  @store.length
55
57
  end
58
+
59
+ def peek
60
+ @store.peek
61
+ end
56
62
  end
57
63
  end
@@ -1,3 +1,3 @@
1
1
  module Coordinator
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -7,6 +7,7 @@ describe 'Coordinator::Base' do
7
7
  Coordinator::Queue.new("medium"),
8
8
  Coordinator::Queue.new("low")
9
9
  ])
10
+ Redis.current.flushall
10
11
  end
11
12
 
12
13
  describe 'adding work' do
@@ -36,4 +37,33 @@ describe 'Coordinator::Base' do
36
37
  assert_equal 2, @coordinator.next_task(["medium"])
37
38
  end
38
39
  end
40
+
41
+ describe 'length_all' do
42
+ it 'returns the total amount of tasks across all queues' do
43
+ @coordinator.add_task("medium", 1)
44
+ @coordinator.add_priority_task("medium", 2)
45
+ @coordinator.add_task("low", 3)
46
+ @coordinator.add_task("high", 4)
47
+ assert_equal 4, @coordinator.length_all
48
+ end
49
+
50
+ it 'returns 0 for no tasks enqueued' do
51
+ assert_equal 0, @coordinator.length_all
52
+ end
53
+ end
54
+
55
+ describe 'peek_all' do
56
+ it 'returns the top item from each queue' do
57
+ @coordinator.add_task("medium", 1)
58
+ @coordinator.add_priority_task("medium", 2)
59
+ @coordinator.add_task("low", 3)
60
+ @coordinator.add_task("high", 4)
61
+
62
+ assert_equal [2,3,4].sort, @coordinator.peek_all.sort
63
+ end
64
+
65
+ it 'returns empty array if all queues are empty' do
66
+ assert_equal [], @coordinator.peek_all
67
+ end
68
+ end
39
69
  end
@@ -63,4 +63,14 @@ describe "Coordinator::Queue" do
63
63
  assert queue.eligible?(3, ["special"]), "override through both"
64
64
  end
65
65
  end
66
+
67
+ describe "peek" do
68
+ it "deserialize the top task but leaves it in the queue" do
69
+ task = {"id" => 123}
70
+ @queue.add_task(task)
71
+
72
+ assert_equal task, @queue.peek
73
+ assert_equal task, @queue.peek # ensure task is still enqueued
74
+ end
75
+ end
66
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coordinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Mercier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -136,3 +136,4 @@ test_files:
136
136
  - test/unit/parallelism_test.rb
137
137
  - test/unit/queue_test.rb
138
138
  - test/unit/redis_queue_test.rb
139
+ has_rdoc: