pigeon 0.4.10 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/pigeon/engine.rb +7 -1
- data/lib/pigeon/task.rb +28 -8
- data/pigeon.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/pigeon/engine.rb
CHANGED
@@ -311,12 +311,18 @@ class Pigeon::Engine
|
|
311
311
|
end
|
312
312
|
|
313
313
|
# Used to defer a block of work for near-immediate execution. Is a
|
314
|
-
# wrapper around EventMachine
|
314
|
+
# wrapper around EventMachine.defer and does not perform as well as using
|
315
315
|
# the alternate dispatch method.
|
316
316
|
def defer(&block)
|
317
317
|
EventMachine.defer(&block)
|
318
318
|
end
|
319
319
|
|
320
|
+
# Schedules a block for execution on the main EventMachine thread. This is
|
321
|
+
# a wrapper around the EventMachine.schedule method.
|
322
|
+
def schedule(&block)
|
323
|
+
EventMachine.schedule(&block)
|
324
|
+
end
|
325
|
+
|
320
326
|
# Shuts down the engine. Will also trigger the before_stop and after_stop
|
321
327
|
# events.
|
322
328
|
def terminate
|
data/lib/pigeon/task.rb
CHANGED
@@ -113,14 +113,7 @@ protected
|
|
113
113
|
end
|
114
114
|
|
115
115
|
rescue Object => e
|
116
|
-
|
117
|
-
|
118
|
-
handle_exception(e) rescue nil
|
119
|
-
|
120
|
-
transition_to_state(:failed) unless (self.failed?)
|
121
|
-
|
122
|
-
self.after_failed
|
123
|
-
self.after_terminated
|
116
|
+
exeption_received(e)
|
124
117
|
ensure
|
125
118
|
after_state(state)
|
126
119
|
|
@@ -158,6 +151,19 @@ protected
|
|
158
151
|
end
|
159
152
|
end
|
160
153
|
|
154
|
+
# This allows a block to be executed in the main event thread where it is
|
155
|
+
# strictly required. Any exceptions generated by the block will be captured
|
156
|
+
# and will cause the task to transition to the failed state.
|
157
|
+
def execute_in_main_thread
|
158
|
+
@engine.schedule do
|
159
|
+
begin
|
160
|
+
yield
|
161
|
+
rescue Object => e
|
162
|
+
exeption_received(e)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
161
167
|
# Called just after the task is initialized.
|
162
168
|
def after_initialized
|
163
169
|
end
|
@@ -194,4 +200,18 @@ protected
|
|
194
200
|
def state_initialized!
|
195
201
|
transition_to_state(:finished)
|
196
202
|
end
|
203
|
+
|
204
|
+
# This method is used to handle an exception and run through the proper
|
205
|
+
# failure handling mechanism. The handle_exception method is provided for
|
206
|
+
# subclasses to customize.
|
207
|
+
def exception_received(e)
|
208
|
+
@exception = e
|
209
|
+
|
210
|
+
handle_exception(e) rescue nil
|
211
|
+
|
212
|
+
transition_to_state(:failed) unless (self.failed?)
|
213
|
+
|
214
|
+
self.after_failed
|
215
|
+
self.after_terminated
|
216
|
+
end
|
197
217
|
end
|
data/pigeon.gemspec
CHANGED