Class: GoodJob::MultiScheduler
- Inherits:
-
Object
- Object
- GoodJob::MultiScheduler
- Defined in:
- lib/good_job/multi_scheduler.rb
Overview
Delegates the interface of a single Scheduler to multiple Schedulers.
Instance Attribute Summary collapse
-
#schedulers ⇒ array<Scheduler>
readonly
List of the scheduler delegates.
Instance Method Summary collapse
-
#create_thread(state = nil) ⇒ Object
Delegates to Scheduler#create_thread.
-
#initialize(schedulers) ⇒ MultiScheduler
constructor
A new instance of MultiScheduler.
-
#restart(wait: true) ⇒ Object
Delegates to Scheduler#restart.
-
#shutdown(wait: true) ⇒ Object
Delegates to Scheduler#shutdown.
-
#shutdown? ⇒ Boolean
Delegates to Scheduler#shutdown?.
Constructor Details
#initialize(schedulers) ⇒ MultiScheduler
Returns a new instance of MultiScheduler.
7 8 9 |
# File 'lib/good_job/multi_scheduler.rb', line 7 def initialize(schedulers) @schedulers = schedulers end |
Instance Attribute Details
#schedulers ⇒ array<Scheduler> (readonly)
Returns List of the scheduler delegates.
5 6 7 |
# File 'lib/good_job/multi_scheduler.rb', line 5 def schedulers @schedulers end |
Instance Method Details
#create_thread(state = nil) ⇒ Object
Delegates to Scheduler#create_thread.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/good_job/multi_scheduler.rb', line 27 def create_thread(state = nil) results = [] if state schedulers.any? do |scheduler| scheduler.create_thread(state).tap { |result| results << result } end else schedulers.each do |scheduler| results << scheduler.create_thread(state) end end if results.any? true elsif results.any? { |result| result == false } false else # rubocop:disable Style/EmptyElse nil end end |
#restart(wait: true) ⇒ Object
Delegates to Scheduler#restart.
22 23 24 |
# File 'lib/good_job/multi_scheduler.rb', line 22 def restart(wait: true) schedulers.each { |s| s.restart(wait: wait) } end |
#shutdown(wait: true) ⇒ Object
Delegates to Scheduler#shutdown.
12 13 14 |
# File 'lib/good_job/multi_scheduler.rb', line 12 def shutdown(wait: true) schedulers.each { |s| s.shutdown(wait: wait) } end |
#shutdown? ⇒ Boolean
Delegates to Scheduler#shutdown?.
17 18 19 |
# File 'lib/good_job/multi_scheduler.rb', line 17 def shutdown? schedulers.all?(&:shutdown?) end |