Sha256: b99efc267e54819c45c2f17f6fbbf1ebde26d2f548c65faf09948bac83f33ecc

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Puppet::Scheduler
  class Scheduler
    def initialize(timer = Puppet::Scheduler::Timer.new)
      @timer = timer
    end

    def run_loop(jobs)
      mark_start_times(jobs, @timer.now)
      until enabled(jobs).empty?
        @timer.wait_for(min_interval_to_next_run_from(jobs, @timer.now))
        run_ready(jobs, @timer.now)
      end
    end

    private

    def enabled(jobs)
      jobs.select(&:enabled?)
    end

    def mark_start_times(jobs, start_time)
      jobs.each do |job|
        job.start_time = start_time
      end
    end

    def min_interval_to_next_run_from(jobs, from_time)
      enabled(jobs).map do |j|
        j.interval_to_next_from(from_time)
      end.min
    end

    def run_ready(jobs, at_time)
      enabled(jobs).each do |j|
        # This check intentionally happens right before each run,
        # instead of filtering on ready schedulers, since one may adjust
        # the readiness of a later one
        if j.ready?(at_time)
          j.run(at_time)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/scheduler/scheduler.rb
puppet-8.10.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.10.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.10.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.9.0 lib/puppet/scheduler/scheduler.rb
puppet-8.9.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.9.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.9.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.8.1 lib/puppet/scheduler/scheduler.rb
puppet-8.8.1-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.8.1-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.8.1-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.7.0 lib/puppet/scheduler/scheduler.rb
puppet-8.7.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.7.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.7.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.6.0 lib/puppet/scheduler/scheduler.rb
puppet-8.6.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.6.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.6.0-universal-darwin lib/puppet/scheduler/scheduler.rb