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, 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
-
.from_configuration(configuration) ⇒ GoodJob::Poller
Creates GoodJob::Poller from a GoodJob::Configuration instance.
Instance Method Summary collapse
-
#initialize(*recipients, poll_interval: nil) ⇒ Poller
constructor
A new instance of Poller.
-
#restart(timeout: -1)) ⇒ void
Restart the poller.
-
#running? ⇒ true, ...
Tests whether the timer is running.
-
#shutdown(timeout: -1)) ⇒ void
Shut down the poller.
-
#shutdown? ⇒ true, ...
Tests whether the timer is shutdown.
Constructor Details
#initialize(*recipients, poll_interval: nil) ⇒ Poller
Returns a new instance of Poller.
36 37 38 39 40 41 42 43 44 |
# File 'lib/good_job/poller.rb', line 36 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? create_timer self.class.instances << self end |
Class Attribute Details
.instances ⇒ Array<GoodJob::Poller>? (readonly)
List of all instantiated Pollers in the current process.
21 |
# File 'lib/good_job/poller.rb', line 21 cattr_reader :instances, default: Concurrent::Array.new, instance_reader: false |
Instance Attribute Details
#recipients ⇒ Array<#call, Array(Object, Symbol)> (readonly)
List of recipients that will receive notifications.
32 33 34 |
# File 'lib/good_job/poller.rb', line 32 def recipients @recipients end |
Class Method Details
.from_configuration(configuration) ⇒ GoodJob::Poller
Creates GoodJob::Poller from a GoodJob::Configuration instance.
26 27 28 |
# File 'lib/good_job/poller.rb', line 26 def self.from_configuration(configuration) GoodJob::Poller.new(poll_interval: configuration.poll_interval) end |
Instance Method Details
#restart(timeout: -1)) ⇒ void
This method returns an undefined value.
Restart the poller. When shutdown, start; or shutdown and start.
79 80 81 82 |
# File 'lib/good_job/poller.rb', line 79 def restart(timeout: -1) shutdown(timeout: timeout) if running? create_timer end |
#running? ⇒ true, ...
Tests whether the timer is running.
48 |
# File 'lib/good_job/poller.rb', line 48 delegate :running?, to: :timer, allow_nil: true |
#shutdown(timeout: -1)) ⇒ void
This method returns an undefined value.
Shut down the poller. Use #shutdown? to determine whether threads have stopped.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/good_job/poller.rb', line 64 def shutdown(timeout: -1) return if timer.nil? || timer.shutdown? timer.shutdown if timer.running? if timer.shuttingdown? && timeout # rubocop:disable Style/GuardClause timer_wait = timeout.negative? ? nil : timeout timer.kill unless timer.wait_for_termination(timer_wait) end end |
#shutdown? ⇒ true, ...
Tests whether the timer is shutdown.
52 53 54 |
# File 'lib/good_job/poller.rb', line 52 def shutdown? timer ? timer.shutdown? : true end |