Sha256: 8228af2d082035c38e8f69d3bd274e1f4ec564566eaee6e49635ba3a131efb55

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

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

    def initialize(schedulers)
      @schedulers = schedulers
    end

    # Delegates to {Scheduler#shutdown}.
    def shutdown(wait: true)
      schedulers.each { |s| s.shutdown(wait: wait) }
    end

    # Delegates to {Scheduler#shutdown?}.
    def shutdown?
      schedulers.all?(&:shutdown?)
    end

    # Delegates to {Scheduler#restart}.
    def restart(wait: true)
      schedulers.each { |s| s.restart(wait: wait) }
    end

    # Delegates to {Scheduler#create_thread}.
    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
good_job-1.7.1 lib/good_job/multi_scheduler.rb
good_job-1.7.0 lib/good_job/multi_scheduler.rb
good_job-1.6.0 lib/good_job/multi_scheduler.rb
good_job-1.5.0 lib/good_job/multi_scheduler.rb
good_job-1.4.1 lib/good_job/multi_scheduler.rb
good_job-1.4.0 lib/good_job/multi_scheduler.rb
good_job-1.3.6 lib/good_job/multi_scheduler.rb
good_job-1.3.5 lib/good_job/multi_scheduler.rb
good_job-1.3.4 lib/good_job/multi_scheduler.rb
good_job-1.3.3 lib/good_job/multi_scheduler.rb
good_job-1.3.2 lib/good_job/multi_scheduler.rb