Sha256: 5f9ecdda6ab4d7c5647eb3de4158829c2ed08565158c506f8b4eae770a2cec16

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Facter
  class InternalFactManager
    @@log = Facter::Log.new(self)

    def resolve_facts(searched_facts)
      searched_facts = filter_internal_facts(searched_facts)

      threads = start_threads(searched_facts)

      join_threads(threads, searched_facts)
    end

    private

    def filter_internal_facts(searched_facts)
      searched_facts.select { |searched_fact| %i[core legacy].include? searched_fact.type }
    end

    def start_threads(searched_facts)
      threads = []
      # only resolve a fact once, even if multiple search facts depend on that fact
      searched_facts
        .uniq { |searched_fact| searched_fact.fact_class.name }
        .each do |searched_fact|
        threads << Thread.new do
          begin
            fact = CoreFact.new(searched_fact)
            fact.create
          rescue StandardError => e
            @@log.error(e.backtrace.join("\n"))
            nil
          end
        end
      end

      threads
    end

    def join_threads(threads, searched_facts)
      resolved_facts = []

      threads.each do |thread|
        thread.join
        resolved_facts << thread.value unless thread.value.nil?
      end

      resolved_facts.flatten!

      FactAugmenter.augment_resolved_facts(searched_facts, resolved_facts)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facter-4.0.25 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.24 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.23 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.22 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.21 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.20 lib/framework/core/fact/internal/internal_fact_manager.rb
facter-4.0.19 lib/framework/core/fact/internal/internal_fact_manager.rb