Sha256: a93f17c3e382318db9f6ec5fd88e1ac7b4b7bfbef76c15cd2cea36a718e1098e
Contents?: true
Size: 1.57 KB
Versions: 21
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true module GoodJob # Delegates the interface of a single {Scheduler} to multiple Schedulers. class MultiScheduler # @return [Array<Scheduler>] List of the scheduler delegates attr_reader :schedulers # @param schedulers [Array<Scheduler>] def initialize(schedulers) @schedulers = schedulers end # Delegates to {Scheduler#running?}. # @return [Boolean, nil] def running? schedulers.all?(&:running?) end # Delegates to {Scheduler#shutdown?}. # @return [Boolean, nil] def shutdown? schedulers.all?(&:shutdown?) end # Delegates to {Scheduler#shutdown}. # @param timeout [Numeric, nil] # @return [void] def shutdown(timeout: -1) GoodJob._shutdown_all(schedulers, timeout: timeout) end # Delegates to {Scheduler#restart}. # @param timeout [Numeric, nil] # @return [void] def restart(timeout: -1) GoodJob._shutdown_all(schedulers, :restart, timeout: timeout) end # Delegates to {Scheduler#create_thread}. # @param state [Hash] # @return [Boolean, nil] 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?(false) false else # rubocop:disable Style/EmptyElse nil end end end end
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
good_job-3.16.0 | lib/good_job/multi_scheduler.rb |