Class: Servolux::Threaded::ThreadContainer
- Inherits:
-
Struct
- Object
- Struct
- Servolux::Threaded::ThreadContainer
- Defined in:
- lib/servolux/threaded.rb
Instance Attribute Summary collapse
-
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#maximum_iterations ⇒ Object
Returns the value of attribute maximum_iterations.
-
#running ⇒ Object
(also: #running?)
Returns the value of attribute running.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #finished_iterations? ⇒ Boolean
- #join(limit = nil) ⇒ Object
- #run(threaded) ⇒ Object
- #start(threaded) ⇒ Object
- #stop ⇒ Object
Instance Attribute Details
#continue_on_error ⇒ Object
Returns the value of attribute continue_on_error
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def continue_on_error @continue_on_error end |
#interval ⇒ Object
Returns the value of attribute interval
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def interval @interval end |
#iterations ⇒ Object
Returns the value of attribute iterations
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def iterations @iterations end |
#maximum_iterations ⇒ Object
Returns the value of attribute maximum_iterations
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def maximum_iterations @maximum_iterations end |
#running ⇒ Object Also known as: running?
Returns the value of attribute running
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def running @running end |
#thread ⇒ Object
Returns the value of attribute thread
206 207 208 |
# File 'lib/servolux/threaded.rb', line 206 def thread @thread end |
Instance Method Details
#finished_iterations? ⇒ Boolean
249 250 251 252 |
# File 'lib/servolux/threaded.rb', line 249 def finished_iterations? return true if maximum_iterations and (iterations >= maximum_iterations) return false end |
#join(limit = nil) ⇒ Object
244 245 246 247 |
# File 'lib/servolux/threaded.rb', line 244 def join( limit = nil ) return if thread.nil? limit ? thread.join(limit) : thread.join end |
#run(threaded) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/servolux/threaded.rb', line 219 def run( threaded ) loop { begin sleep interval if running? break unless running? threaded.run self.iterations += 1 break if finished_iterations? rescue SystemExit; raise rescue Exception => err if continue_on_error threaded.logger.error err else threaded.logger.fatal err raise err end end } ensure if threaded.respond_to?(:after_stopping) and !self.running threaded.after_stopping end self.running = false end |
#start(threaded) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/servolux/threaded.rb', line 207 def start( threaded ) self.running = true self.iterations = 0 self.thread = Thread.new { run threaded } Thread.pass end |
#stop ⇒ Object
214 215 216 217 |
# File 'lib/servolux/threaded.rb', line 214 def stop self.running = false thread.wakeup end |