pigeon 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -30,6 +30,12 @@ class Pigeon::Scheduler
30
30
  end
31
31
  end
32
32
 
33
+ # Add a single task to the schedule. When subclassing, override the private
34
+ # enqueue_task method instead.
35
+ def <<(task)
36
+ enqueue_task(task)
37
+ end
38
+
33
39
  # Returns the default queue used for scheduling.
34
40
  def default_queue
35
41
  @queues[nil]
@@ -78,6 +84,11 @@ class Pigeon::Scheduler
78
84
  @state == :stopped
79
85
  end
80
86
 
87
+ # Returns true if there are no scheduled tasks, false otherwise.
88
+ def empty?
89
+ self.queue_size == 0
90
+ end
91
+
81
92
  # Returns the number of tasks that have been queued up.
82
93
  def queue_length
83
94
  @queues.inject(0) do |length, (name, queue)|
data/pigeon.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pigeon}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tadman"]
@@ -4,8 +4,8 @@ class PigeonProcessorTest < Test::Unit::TestCase
4
4
  class TaggedTask < Pigeon::Task
5
5
  attr_accessor :tag
6
6
 
7
- def initialize(engine, tag)
8
- super(engine)
7
+ def initialize(tag, options = nil)
8
+ super(options)
9
9
  @tag = tag
10
10
  end
11
11
 
@@ -14,8 +14,14 @@ class PigeonProcessorTest < Test::Unit::TestCase
14
14
  end
15
15
  end
16
16
 
17
- def engine
18
- @engine ||= Pigeon::Engine.new
17
+ def setup
18
+ @engine = Pigeon::Engine.new
19
+
20
+ Pigeon::Engine.register_engine(@engine)
21
+ end
22
+
23
+ def teardown
24
+ Pigeon::Engine.unregister_engine(@engine)
19
25
  end
20
26
 
21
27
  def test_empty_processor
@@ -25,7 +31,7 @@ class PigeonProcessorTest < Test::Unit::TestCase
25
31
 
26
32
  assert_equal false, processor.task?
27
33
 
28
- assert_equal true, processor.accept?(Pigeon::Task.new(engine))
34
+ assert_equal true, processor.accept?(Pigeon::Task.new)
29
35
 
30
36
  assert processor.id
31
37
  end
@@ -39,12 +45,12 @@ class PigeonProcessorTest < Test::Unit::TestCase
39
45
 
40
46
  assert_equal false, processor.task?
41
47
 
42
- queue << TaggedTask.new(engine, 0)
48
+ queue << TaggedTask.new(0)
43
49
 
44
50
  assert_equal false, processor.task?
45
51
  assert_equal 1, queue.length
46
52
 
47
- queue << TaggedTask.new(engine, 1)
53
+ queue << TaggedTask.new(1)
48
54
 
49
55
  assert_equal true, processor.task?
50
56
  assert_equal 1, queue.length
@@ -60,7 +66,7 @@ class PigeonProcessorTest < Test::Unit::TestCase
60
66
  queue = Pigeon::Queue.new
61
67
 
62
68
  100.times do |n|
63
- queue << TaggedTask.new(engine, n)
69
+ queue << TaggedTask.new(n)
64
70
  end
65
71
 
66
72
  processor = Pigeon::Processor.new(queue)
@@ -75,7 +81,7 @@ class PigeonProcessorTest < Test::Unit::TestCase
75
81
  count = 10000
76
82
 
77
83
  count.times do |n|
78
- queue << TaggedTask.new(engine, n)
84
+ queue << TaggedTask.new(n)
79
85
  end
80
86
 
81
87
  assert_equal count, queue.length
@@ -4,8 +4,8 @@ class PigeonQueueTest < Test::Unit::TestCase
4
4
  class TaggedTask < Pigeon::Task
5
5
  attr_accessor :tag
6
6
 
7
- def initialize(engine, tag)
8
- super(engine)
7
+ def initialize(tag, options = nil)
8
+ super(options)
9
9
  @tag = tag
10
10
  end
11
11
 
@@ -14,8 +14,14 @@ class PigeonQueueTest < Test::Unit::TestCase
14
14
  end
15
15
  end
16
16
 
17
- def engine
18
- @engine ||= Pigeon::Engine.new
17
+ def setup
18
+ @engine = Pigeon::Engine.new
19
+
20
+ Pigeon::Engine.register_engine(@engine)
21
+ end
22
+
23
+ def teardown
24
+ Pigeon::Engine.unregister_engine(@engine)
19
25
  end
20
26
 
21
27
  def test_empty_state
@@ -30,7 +36,7 @@ class PigeonQueueTest < Test::Unit::TestCase
30
36
  def test_cycling
31
37
  queue = Pigeon::Queue.new
32
38
 
33
- task = Pigeon::Task.new(engine)
39
+ task = Pigeon::Task.new
34
40
 
35
41
  assert_equal task, queue << task
36
42
 
@@ -50,7 +56,7 @@ class PigeonQueueTest < Test::Unit::TestCase
50
56
  queue = Pigeon::Queue.new
51
57
 
52
58
  tasks = (0..9).to_a.collect do |n|
53
- queue << TaggedTask.new(engine, n)
59
+ queue << TaggedTask.new(n)
54
60
  end
55
61
 
56
62
  assert_equal (0..9).to_a, tasks.to_a.collect(&:tag)
@@ -83,7 +89,7 @@ class PigeonQueueTest < Test::Unit::TestCase
83
89
  assert_equal 0, queue.length(:over_7)
84
90
  assert_equal true, queue.empty?(:over_7)
85
91
 
86
- new_task = queue << TaggedTask.new(engine, 10)
92
+ new_task = queue << TaggedTask.new(10)
87
93
 
88
94
  assert_equal new_task, queue.peek(:over_7)
89
95
  assert_equal 1, queue.length(:over_7)
@@ -100,7 +106,7 @@ class PigeonQueueTest < Test::Unit::TestCase
100
106
  queue = Pigeon::Queue.new
101
107
 
102
108
  tasks = (0..9).to_a.collect do |n|
103
- queue << TaggedTask.new(engine, n)
109
+ queue << TaggedTask.new(n)
104
110
  end
105
111
 
106
112
  queue.filter(:odd) do |task|
@@ -121,11 +127,11 @@ class PigeonQueueTest < Test::Unit::TestCase
121
127
  added_odd = task
122
128
  end
123
129
 
124
- queue << TaggedTask.new(engine, 10)
130
+ queue << TaggedTask.new(10)
125
131
 
126
132
  assert_equal nil, added_odd
127
133
 
128
- odd_1 = queue << TaggedTask.new(engine, 11)
134
+ odd_1 = queue << TaggedTask.new(11)
129
135
 
130
136
  assert_equal odd_1, added_odd
131
137
 
@@ -144,13 +150,13 @@ class PigeonQueueTest < Test::Unit::TestCase
144
150
  assert_equal 7, queue.length
145
151
  assert_equal 1, queue.length(:odd)
146
152
 
147
- queue << TaggedTask.new(engine, 12)
153
+ queue << TaggedTask.new(12)
148
154
 
149
155
  assert_equal nil, claimed_task
150
156
  assert_equal 8, queue.length
151
157
  assert_equal 1, queue.length(:odd)
152
158
 
153
- odd_2 = queue << TaggedTask.new(engine, 13)
159
+ odd_2 = queue << TaggedTask.new(13)
154
160
 
155
161
  # Adding a task that matches the filter triggers the callback.
156
162
  assert_equal odd_2, claimed_task
@@ -162,12 +168,12 @@ class PigeonQueueTest < Test::Unit::TestCase
162
168
  claimed_task = nil
163
169
  has_run = false
164
170
 
165
- queue << TaggedTask.new(engine, 14)
171
+ queue << TaggedTask.new(14)
166
172
 
167
173
  assert_equal nil, claimed_task
168
174
  assert_equal false, has_run
169
175
 
170
- odd_2 = queue << TaggedTask.new(engine, 15)
176
+ odd_2 = queue << TaggedTask.new(15)
171
177
 
172
178
  assert_equal odd_2, claimed_task
173
179
  assert_equal true, has_run
@@ -183,11 +189,11 @@ class PigeonQueueTest < Test::Unit::TestCase
183
189
  if (task.tag < 10)
184
190
  queue.claim(task)
185
191
 
186
- queue << TaggedTask.new(engine, task.tag + 1)
192
+ queue << TaggedTask.new(task.tag + 1)
187
193
  end
188
194
  end
189
195
 
190
- queue << TaggedTask.new(engine, 0)
196
+ queue << TaggedTask.new(0)
191
197
 
192
198
  assert queue.peek
193
199
  assert_equal 10, queue.peek.tag
@@ -4,8 +4,8 @@ class PigeonSchedulerTest < Test::Unit::TestCase
4
4
  class TaggedTask < Pigeon::Task
5
5
  attr_accessor :tag
6
6
 
7
- def initialize(engine, tag)
8
- super(engine)
7
+ def initialize(tag, options = nil)
8
+ super(options)
9
9
  @tag = tag
10
10
  end
11
11
 
@@ -14,14 +14,22 @@ class PigeonSchedulerTest < Test::Unit::TestCase
14
14
  end
15
15
  end
16
16
 
17
- def engine
18
- @engine ||= Pigeon::Engine.new
17
+ def setup
18
+ @engine = Pigeon::Engine.new
19
+
20
+ Pigeon::Engine.register_engine(@engine)
21
+ end
22
+
23
+ def teardown
24
+ Pigeon::Engine.unregister_engine(@engine)
19
25
  end
20
26
 
21
27
  def test_defaults
22
28
  scheduler = Pigeon::Scheduler.new
23
29
 
24
30
  assert_equal true, scheduler.default_queue.empty?
31
+ assert_equal 0, scheduler.queue_size
32
+ assert_equal true, scheduler.empty?
25
33
  end
26
34
 
27
35
  def test_queued
@@ -32,7 +40,7 @@ class PigeonSchedulerTest < Test::Unit::TestCase
32
40
  count = 1000
33
41
 
34
42
  count.times do |n|
35
- queue << TaggedTask.new(engine, n)
43
+ queue << TaggedTask.new(n)
36
44
  end
37
45
 
38
46
  assert_eventually(5) do
@@ -52,8 +60,8 @@ class PigeonSchedulerTest < Test::Unit::TestCase
52
60
 
53
61
  backlog = [ ]
54
62
  count.times do |n|
55
- scheduler.add(TaggedTask.new(engine, n * 2 + 1))
56
- backlog << TaggedTask.new(engine, n * 2)
63
+ scheduler.add(TaggedTask.new(n * 2 + 1))
64
+ backlog << TaggedTask.new(n * 2)
57
65
  end
58
66
 
59
67
  scheduler.add(backlog)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - tadman