Sha256: 170eced96d06f561380a93bc183e8773a82dfe778e35f70c703b8d11e0e41af4

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)
      while not 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.3.0 lib/puppet/scheduler/scheduler.rb
puppet-8.3.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.3.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.3.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.3.1 lib/puppet/scheduler/scheduler.rb
puppet-8.3.1-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.3.1-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.3.1-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.2.0 lib/puppet/scheduler/scheduler.rb
puppet-8.2.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.2.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.2.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.1.0 lib/puppet/scheduler/scheduler.rb
puppet-8.1.0-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.1.0-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.1.0-universal-darwin lib/puppet/scheduler/scheduler.rb
puppet-8.0.1 lib/puppet/scheduler/scheduler.rb
puppet-8.0.1-x86-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.0.1-x64-mingw32 lib/puppet/scheduler/scheduler.rb
puppet-8.0.1-universal-darwin lib/puppet/scheduler/scheduler.rb