Class: Workhorse::Poller

Inherits:
Object
  • Object
show all
Defined in:
lib/workhorse/poller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/workhorse/poller.rb', line 4

def table
  @table
end

#workerObject (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

Returns:

  • (Boolean)


13
14
15
# File 'lib/workhorse/poller.rb', line 13

def running?
  @running
end

#shutdownObject



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

#startObject



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

#waitObject



40
41
42
# File 'lib/workhorse/poller.rb', line 40

def wait
  @thread.join
end