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:



56
57
58
# File 'lib/facter/custom_facts/core/resolvable.rb', line 56

def flush
  @on_flush_block&.call
end

#limitNumeric

Deprecated.

Use timeout instead.

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

Returns:

  • (Numeric)


24
25
26
27
# File 'lib/facter/custom_facts/core/resolvable.rb', line 24

def limit
  Facter::Log.new(self).warnonce('limit is deprecated and will be removed in a future version, use timeout instead')
  @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:



45
46
47
# File 'lib/facter/custom_facts/core/resolvable.rb', line 45

def on_flush(&block)
  @on_flush_block = block
end

#valueObject

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.

Resolves the fact's value or loggs an error if the value couldn't be resolved.

(except Timeout::Error or Narmalization::NarmalizationError in which case an error message is logged and the execution isn't suspended).

Raises:

  • Facter::ResolveCustomFactError if an error was raised



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/facter/custom_facts/core/resolvable.rb', line 71

def value
  result = nil

  with_timing do
    Timeout.timeout(@timeout || 0) do
      result = resolve_value
    end
  end

  LegacyFacter::Util::Normalization.normalize(result)
rescue Timeout::Error => e
  Facter.log_exception(e, "Timed out after #{@timeout || 0} 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