@@ -25,9 +25,7 @@ module Concurrent
25
25
# Should the task experience an unrecoverable crash only the task thread will
26
26
# crash. This makes the `TimerTask` very fault tolerant. Additionally, the
27
27
# `TimerTask` thread can respond to the success or failure of the task,
28
- # performing logging or ancillary operations. `TimerTask` can also be
29
- # configured with a timeout value allowing it to kill a task that runs too
30
- # long.
28
+ # performing logging or ancillary operations.
31
29
#
32
30
# One other advantage of `TimerTask` is that it forces the business logic to
33
31
# be completely decoupled from the concurrency logic. The business logic can
@@ -48,9 +46,7 @@ module Concurrent
48
46
# {http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
49
47
# Observable} module. On execution the `TimerTask` will notify the observers
50
48
# with three arguments: time of execution, the result of the block (or nil on
51
- # failure), and any raised exceptions (or nil on success). If the timeout
52
- # interval is exceeded the observer will receive a `Concurrent::TimeoutError`
53
- # object as the third argument.
49
+ # failure), and any raised exceptions (or nil on success).
54
50
#
55
51
# @!macro copy_options
56
52
#
@@ -59,20 +55,18 @@ module Concurrent
59
55
# task.execute
60
56
#
61
57
# task.execution_interval #=> 60 (default)
62
- # task.timeout_interval #=> 30 (default)
63
58
#
64
59
# # wait 60 seconds...
65
60
# #=> 'Boom!'
66
61
#
67
62
# task.shutdown #=> true
68
63
#
69
- # @example Configuring `:execution_interval` and `:timeout_interval`
70
- # task = Concurrent::TimerTask.new(execution_interval: 5, timeout_interval: 5 ) do
64
+ # @example Configuring `:execution_interval`
65
+ # task = Concurrent::TimerTask.new(execution_interval: 5) do
71
66
# puts 'Boom!'
72
67
# end
73
68
#
74
69
# task.execution_interval #=> 5
75
- # task.timeout_interval #=> 5
76
70
#
77
71
# @example Immediate execution with `:run_now`
78
72
# task = Concurrent::TimerTask.new(run_now: true){ puts 'Boom!' }
@@ -115,15 +109,13 @@ module Concurrent
115
109
# def update(time, result, ex)
116
110
# if result
117
111
# print "(#{time}) Execution successfully returned #{result}\n"
118
- # elsif ex.is_a?(Concurrent::TimeoutError)
119
- # print "(#{time}) Execution timed out\n"
120
112
# else
121
113
# print "(#{time}) Execution failed with error #{ex}\n"
122
114
# end
123
115
# end
124
116
# end
125
117
#
126
- # task = Concurrent::TimerTask.new(execution_interval: 1, timeout_interval: 1 ){ 42 }
118
+ # task = Concurrent::TimerTask.new(execution_interval: 1){ 42 }
127
119
# task.add_observer(TaskObserver.new)
128
120
# task.execute
129
121
# sleep 4
@@ -133,7 +125,7 @@ module Concurrent
133
125
# #=> (2013-10-13 19:09:00 -0400) Execution successfully returned 42
134
126
# task.shutdown
135
127
#
136
- # task = Concurrent::TimerTask.new(execution_interval: 1, timeout_interval: 1 ){ sleep }
128
+ # task = Concurrent::TimerTask.new(execution_interval: 1){ sleep }
137
129
# task.add_observer(TaskObserver.new)
138
130
# task.execute
139
131
#
@@ -160,17 +152,12 @@ class TimerTask < RubyExecutorService
160
152
# Default `:execution_interval` in seconds.
161
153
EXECUTION_INTERVAL = 60
162
154
163
- # Default `:timeout_interval` in seconds.
164
- TIMEOUT_INTERVAL = 30
165
-
166
155
# Create a new TimerTask with the given task and configuration.
167
156
#
168
157
# @!macro timer_task_initialize
169
158
# @param [Hash] opts the options defining task execution.
170
159
# @option opts [Integer] :execution_interval number of seconds between
171
160
# task executions (default: EXECUTION_INTERVAL)
172
- # @option opts [Integer] :timeout_interval number of seconds a task can
173
- # run before it is considered to have failed (default: TIMEOUT_INTERVAL)
174
161
# @option opts [Boolean] :run_now Whether to run the task immediately
175
162
# upon instantiation or to wait until the first # execution_interval
176
163
# has passed (default: false)
@@ -252,24 +239,6 @@ def execution_interval=(value)
252
239
end
253
240
end
254
241
255
- # @!attribute [rw] timeout_interval
256
- # @return [Fixnum] Number of seconds the task can run before it is
257
- # considered to have failed.
258
- def timeout_interval
259
- synchronize { @timeout_interval }
260
- end
261
-
262
- # @!attribute [rw] timeout_interval
263
- # @return [Fixnum] Number of seconds the task can run before it is
264
- # considered to have failed.
265
- def timeout_interval = ( value )
266
- if ( value = value . to_f ) <= 0.0
267
- raise ArgumentError . new ( 'must be greater than zero' )
268
- else
269
- synchronize { @timeout_interval = value }
270
- end
271
- end
272
-
273
242
private :post , :<<
274
243
275
244
private
@@ -278,7 +247,6 @@ def ns_initialize(opts, &task)
278
247
set_deref_options ( opts )
279
248
280
249
self . execution_interval = opts [ :execution ] || opts [ :execution_interval ] || EXECUTION_INTERVAL
281
- self . timeout_interval = opts [ :timeout ] || opts [ :timeout_interval ] || TIMEOUT_INTERVAL
282
250
@run_now = opts [ :now ] || opts [ :run_now ]
283
251
@executor = Concurrent ::SafeTaskExecutor . new ( task )
284
252
@running = Concurrent ::AtomicBoolean . new ( false )
@@ -308,7 +276,6 @@ def schedule_next_task(interval = execution_interval)
308
276
# @!visibility private
309
277
def execute_task ( completion )
310
278
return nil unless @running . true?
311
- ScheduledTask . execute ( timeout_interval , args : [ completion ] , &method ( :timeout_task ) )
312
279
_success , value , reason = @executor . execute ( self )
313
280
if completion . try?
314
281
self . value = value
@@ -320,14 +287,5 @@ def execute_task(completion)
320
287
end
321
288
nil
322
289
end
323
-
324
- # @!visibility private
325
- def timeout_task ( completion )
326
- return unless @running . true?
327
- if completion . try?
328
- schedule_next_task
329
- observers . notify_observers ( Time . now , nil , Concurrent ::TimeoutError . new )
330
- end
331
- end
332
290
end
333
291
end
0 commit comments