Class: Workhorse::Poller
- Inherits:
-
Object
- Object
- Workhorse::Poller
- Defined in:
- lib/workhorse/poller.rb
Constant Summary collapse
- MIN_LOCK_TIMEOUT =
In seconds
0.1
- MAX_LOCK_TIMEOUT =
In seconds
1.0
- ORACLE_LOCK_MODE =
X_MODE (exclusive)
6
- ORACLE_LOCK_HANDLE =
Randomly chosen number
478_564_848
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.
-
#instant_repoll! ⇒ Object
Call this to interrupt current sleep and perform the next poll as soon as possible, then resume in the normal polling interval.
- #running? ⇒ Boolean
- #shutdown ⇒ Object
- #start ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(worker) ⇒ Poller
Returns a new instance of Poller.
12 13 14 15 16 17 18 19 20 |
# File 'lib/workhorse/poller.rb', line 12 def initialize(worker) @worker = worker @running = false @table = Workhorse::DbJob.arel_table @is_oracle = ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced' @instant_repoll = Concurrent::AtomicBoolean.new(false) @global_lock_fails = 0 @max_global_lock_fails_reached = false end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
10 11 12 |
# File 'lib/workhorse/poller.rb', line 10 def table @table end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
9 10 11 |
# File 'lib/workhorse/poller.rb', line 9 def worker @worker end |
Instance Method Details
#instant_repoll! ⇒ Object
Call this to interrupt current sleep and perform the next poll as soon as possible, then resume in the normal polling interval.
63 64 65 66 |
# File 'lib/workhorse/poller.rb', line 63 def instant_repoll! worker.log 'Aborting next sleep to perform instant repoll', :debug @instant_repoll.make_true end |
#running? ⇒ Boolean
22 23 24 |
# File 'lib/workhorse/poller.rb', line 22 def running? @running end |
#shutdown ⇒ Object
51 52 53 54 55 |
# File 'lib/workhorse/poller.rb', line 51 def shutdown fail 'Poller is not running.' unless running? @running = false wait end |
#start ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/workhorse/poller.rb', line 26 def start fail 'Poller is already running.' if running? @running = true clean_stuck_jobs! if Workhorse.clean_stuck_jobs @thread = Thread.new do loop do break unless running? begin poll sleep rescue Exception => e worker.log %(Poll encountered exception:\n#{e.}\n#{e.backtrace.join("\n")}) worker.log 'Worker shutting down...' Workhorse.on_exception.call(e) unless Workhorse.silence_poller_exceptions @running = false worker.instance_variable_get(:@pool).shutdown break end end end end |
#wait ⇒ Object
57 58 59 |
# File 'lib/workhorse/poller.rb', line 57 def wait @thread.join end |