Sha256: 4c6f03369e32d2dc426679773da9e7442cd9a3f69a0f28e92ee9ec773021b26e

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 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#running?}.
    def running?
      schedulers.all?(&:running?)
    end

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

    # Delegates to {Scheduler#shutdown}.
    def shutdown(timeout: -1)
      GoodJob._shutdown_all(schedulers, timeout: timeout)
    end

    # Delegates to {Scheduler#restart}.
    def restart(timeout: -1)
      GoodJob._shutdown_all(schedulers, :restart, timeout: timeout)
    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?(false)
        false
      else # rubocop:disable Style/EmptyElse
        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
good_job-1.9.3 lib/good_job/multi_scheduler.rb
good_job-1.9.2 lib/good_job/multi_scheduler.rb
good_job-1.9.1 lib/good_job/multi_scheduler.rb
good_job-1.9.0 lib/good_job/multi_scheduler.rb