Class: GoodJob::Poller
- Inherits:
-
Object
- Object
- GoodJob::Poller
- Defined in:
- lib/good_job/poller.rb
Overview
Pollers regularly wake up execution threads to check for new work.
Constant Summary collapse
- DEFAULT_TIMER_OPTIONS =
Defaults for instance of Concurrent::TimerTask. The timer controls how and when sleeping threads check for new work.
{ execution_interval: Configuration::DEFAULT_POLL_INTERVAL, timeout_interval: 1, run_now: true, }.freeze
Class Attribute Summary collapse
-
.instances ⇒ array<GoodJob:Poller>
readonly
List of all instantiated Pollers in the current process.
Instance Attribute Summary collapse
-
#recipients ⇒ Array<#call, Array(Object, Symbol)>
readonly
List of recipients that will receive notifications.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*recipients, poll_interval: nil) ⇒ Poller
constructor
A new instance of Poller.
-
#restart(wait: true) ⇒ void
Restart the poller.
-
#shutdown(wait: true) ⇒ void
Shut down the poller.
-
#shutdown? ⇒ true, ...
Tests whether the poller is shutdown.
Constructor Details
#initialize(*recipients, poll_interval: nil) ⇒ Poller
Returns a new instance of Poller.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/good_job/poller.rb', line 32 def initialize(*recipients, poll_interval: nil) @recipients = Concurrent::Array.new(recipients) @timer_options = DEFAULT_TIMER_OPTIONS.dup @timer_options[:execution_interval] = poll_interval if poll_interval.present? self.class.instances << self create_pool end |
Class Attribute Details
.instances ⇒ array<GoodJob:Poller> (readonly)
List of all instantiated Pollers in the current process.
20 |
# File 'lib/good_job/poller.rb', line 20 cattr_reader :instances, default: [], instance_reader: false |
Instance Attribute Details
#recipients ⇒ Array<#call, Array(Object, Symbol)> (readonly)
List of recipients that will receive notifications.
28 29 30 |
# File 'lib/good_job/poller.rb', line 28 def recipients @recipients end |
Class Method Details
Instance Method Details
#restart(wait: true) ⇒ void
This method returns an undefined value.
Restart the poller. When shutdown, start; or shutdown and start.
66 67 68 69 |
# File 'lib/good_job/poller.rb', line 66 def restart(wait: true) shutdown(wait: wait) create_pool end |
#shutdown(wait: true) ⇒ void
This method returns an undefined value.
Shut down the poller. If wait is true, the poller will wait for background thread to shutdown. If wait is false, this method will return immediately even though threads may still be running. Use #shutdown? to determine whether threads have stopped.
49 50 51 52 53 54 |
# File 'lib/good_job/poller.rb', line 49 def shutdown(wait: true) return unless @timer&.running? @timer.shutdown @timer.wait_for_termination if wait end |
#shutdown? ⇒ true, ...
Tests whether the poller is shutdown.
58 59 60 |
# File 'lib/good_job/poller.rb', line 58 def shutdown? !@timer&.running? end |