Module: LegacyFacter::Core::Resolvable

Included in:
Facter::Core::Aggregate, Facter::Util::Resolution
Defined in:
lib/facter/custom_facts/core/resolvable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/facter/custom_facts/core/resolvable.rb', line 18

def logger
  @logger
end

#timeoutInteger

The timeout, in seconds, for evaluating this resolution.

Returns:

  • (Integer)


17
18
19
# File 'lib/facter/custom_facts/core/resolvable.rb', line 17

def timeout
  @timeout
end

Instance Method Details

#flushObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

flush executes the block, if any, stored by the #on_flush method

See Also:



58
59
60
# File 'lib/facter/custom_facts/core/resolvable.rb', line 58

def flush
  @on_flush_block&.call
end

#limitNumeric

Return the timeout period for resolving a value. (see #timeout)

Returns:

  • (Numeric)


27
28
29
# File 'lib/facter/custom_facts/core/resolvable.rb', line 27

def limit
  @timeout || 0
end

#on_flush(&block) ⇒ Object

on_flush accepts a block and executes the block when the resolution’s value is flushed. This makes it possible to model a single, expensive system call inside of a Ruby object and then define multiple dynamic facts which resolve by sending messages to the model instance. If one of the dynamic facts is flushed then it can, in turn, flush the data stored in the model instance to keep all of the dynamic facts in sync without making multiple, expensive, system calls.

Please see the Solaris zones fact for an example of how this feature may be used.

See Also:



47
48
49
# File 'lib/facter/custom_facts/core/resolvable.rb', line 47

def on_flush(&block)
  @on_flush_block = block
end

#valueObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/facter/custom_facts/core/resolvable.rb', line 62

def value
  result = nil

  with_timing do
    Timeout.timeout(limit) do
      result = resolve_value
    end
  end

  LegacyFacter::Util::Normalization.normalize(result)
rescue Timeout::Error => e
  Facter.log_exception(e, "Timed out after #{limit} seconds while resolving #{qualified_name}")

  nil
rescue LegacyFacter::Util::Normalization::NormalizationError => e
  Facter.log_exception(e, "Fact resolution #{qualified_name} resolved to an invalid value: #{e.message}")

  nil
rescue StandardError => e
  Facter.log_exception(e, "Error while resolving custom fact #{qualified_name}: #{e.message}")

  raise Facter::ResolveCustomFactError
end