Class: Workhorse::Poller
- Inherits:
-
Object
- Object
- Workhorse::Poller
- Defined in:
- lib/workhorse/poller.rb
Instance Attribute Summary collapse
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
-
#initialize(worker) ⇒ Poller
constructor
A new instance of Poller.
- #running? ⇒ Boolean
- #shutdown ⇒ Object
- #start ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(worker) ⇒ Poller
Returns a new instance of Poller.
5 6 7 8 |
# File 'lib/workhorse/poller.rb', line 5 def initialize(worker) @worker = worker @running = false end |
Instance Attribute Details
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
3 4 5 |
# File 'lib/workhorse/poller.rb', line 3 def worker @worker end |
Instance Method Details
#running? ⇒ Boolean
10 11 12 |
# File 'lib/workhorse/poller.rb', line 10 def running? @running end |
#shutdown ⇒ Object
31 32 33 34 35 |
# File 'lib/workhorse/poller.rb', line 31 def shutdown fail 'Poller is not running.' unless running? @running = false wait end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/workhorse/poller.rb', line 14 def start fail 'Poller is already running.' if running? @running = true @thread = Thread.new do begin loop do poll break unless running? sleep end rescue => e worker.log %(Poller stopped with exception:\n#{e.message}\n#{e.backtrace.join("\n")}) end end end |
#wait ⇒ Object
37 38 39 |
# File 'lib/workhorse/poller.rb', line 37 def wait @thread.join end |