Module: LoopHard
- Defined in:
- lib/loop_hard.rb,
lib/loop_hard/loop.rb,
lib/loop_hard/logger.rb,
lib/loop_hard/version.rb,
lib/loop_hard/signal_trap.rb,
lib/loop_hard/sidekiq_trap.rb,
lib/loop_hard/timeout_trap.rb
Overview
Have loops with a timeout, that listen to signals to know if they should stop prematurely
Defined Under Namespace
Modules: SidekiqTrap, SignalTrap, TimeoutTrap
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.logger ⇒ Object
Set the Logger for LoopHard.
Class Method Summary collapse
-
.loop(options = {}) ⇒ Object
Loop until the passed in block breaks, or until one of the traps open.
Class Attribute Details
.logger ⇒ Object
Set the Logger for LoopHard
6 7 8 |
# File 'lib/loop_hard/logger.rb', line 6 def logger @logger ||= Logger.new($stdout) end |
Class Method Details
.loop(options = {}) ⇒ Object
Loop until the passed in block breaks, or until one of the traps open. Will yield to the block passed in until it decides to stop looping. Your block should break once it’s done.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/loop_hard/loop.rb', line 9 def loop( = {}) = { timeout: nil, traps: [SidekiqTrap, SignalTrap, TimeoutTrap] } = .merge() [:maximum_end_time] = ([:timeout] ? Time.now + [:timeout] : nil) while continue_looping?() yield # Block will call "break" once it's out of rows, which will break this loop end end |