pigeon 0.5.0 → 0.5.1

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 CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
data/lib/pigeon/engine.rb CHANGED
@@ -224,6 +224,12 @@ class Pigeon::Engine
224
224
  def self.unregister_engine(engine)
225
225
  @engines.delete(engine)
226
226
  end
227
+
228
+ # Schedules a block for execution on the main EventMachine thread. This is
229
+ # a wrapper around the EventMachine.schedule method.
230
+ def self.execute_in_main_thread(&block)
231
+ EventMachine.schedule(&block)
232
+ end
227
233
 
228
234
  # == Instance Methods =====================================================
229
235
 
@@ -319,7 +325,7 @@ class Pigeon::Engine
319
325
 
320
326
  # Schedules a block for execution on the main EventMachine thread. This is
321
327
  # a wrapper around the EventMachine.schedule method.
322
- def schedule(&block)
328
+ def execute_in_main_thread(&block)
323
329
  EventMachine.schedule(&block)
324
330
  end
325
331
 
@@ -70,9 +70,22 @@ class Pigeon::Processor
70
70
  end
71
71
 
72
72
  protected
73
+ # This method is called before a task is started. The default handler does
74
+ # nothing but this can be customized in a subclass.
75
+ def before_task(task)
76
+ end
77
+
78
+ # This method is called each time a task is completed or fails. The default
79
+ # handler does nothing but this can be customized in a subclass.
80
+ def after_task(task)
81
+ end
82
+
83
+ # Used to reliably switch to the next task and coordinates the required
84
+ # hand-off from one to the next.
73
85
  def switch_to_next_task!
74
86
  @lock.synchronize do
75
87
  if (@task)
88
+ after_task(@task)
76
89
  @task.processor = nil
77
90
  end
78
91
 
@@ -80,6 +93,7 @@ protected
80
93
 
81
94
  if (@queue)
82
95
  if (@task = @queue.pop(&@filter))
96
+ before_task(@task)
83
97
  @task.run!(self) do
84
98
  switch_to_next_task!
85
99
  end
data/lib/pigeon/task.rb CHANGED
@@ -113,7 +113,7 @@ protected
113
113
  end
114
114
 
115
115
  rescue Object => e
116
- exeption_received(e)
116
+ exception_received(e)
117
117
  ensure
118
118
  after_state(state)
119
119
 
@@ -155,11 +155,11 @@ protected
155
155
  # strictly required. Any exceptions generated by the block will be captured
156
156
  # and will cause the task to transition to the failed state.
157
157
  def execute_in_main_thread
158
- @engine.schedule do
158
+ @engine.execute_in_main_thread do
159
159
  begin
160
160
  yield
161
161
  rescue Object => e
162
- exeption_received(e)
162
+ exception_received(e)
163
163
  end
164
164
  end
165
165
  end
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.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tadman"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pigeon
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - tadman
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  requirements: []
91
91
 
92
92
  rubyforge_project:
93
- rubygems_version: 1.5.2
93
+ rubygems_version: 1.5.3
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: Simple daemonized EventMachine engine framework with plug-in support