Class: Workhorse::Poller
- Inherits:
-
Object
- Object
- Workhorse::Poller
- Defined in:
- lib/workhorse/poller.rb
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#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.
6 7 8 9 10 11 |
# File 'lib/workhorse/poller.rb', line 6 def initialize(worker) @worker = worker @running = false @table = Workhorse::DbJob.arel_table @is_oracle = ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced' end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
4 5 6 |
# File 'lib/workhorse/poller.rb', line 4 def table @table end |
#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
13 14 15 |
# File 'lib/workhorse/poller.rb', line 13 def running? @running end |
#shutdown ⇒ Object
34 35 36 37 38 |
# File 'lib/workhorse/poller.rb', line 34 def shutdown fail 'Poller is not running.' unless running? @running = false wait end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/workhorse/poller.rb', line 17 def start fail 'Poller is already running.' if running? @running = true @thread = Thread.new do begin loop do break unless running? poll sleep end rescue Exception => e worker.log %(Poller stopped with exception:\n#{e.message}\n#{e.backtrace.join("\n")}) end end end |
#wait ⇒ Object
40 41 42 |
# File 'lib/workhorse/poller.rb', line 40 def wait @thread.join end |