Module: LegacyFacter::Core::Resolvable

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

Overview

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#timeoutInteger

The timeout, in seconds, for evaluating this resolution.

Returns:

  • (Integer)

Since:

  • 2.0.0



17
18
19
# File 'lib/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:

  • Facter::Util::Fact#flush
  • Facter::Util::Resolution#on_flush

Since:

  • 2.0.0



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

def flush
  @on_flush_block&.call
end

#limitNumeric

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

Returns:

  • (Numeric)

Since:

  • 2.0.0



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

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:

  • Facter::Util::Fact#flush
  • Facter::Util::Resolution#flush

Since:

  • 2.0.0



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

def on_flush(&block)
  @on_flush_block = block
end

#valueObject

Since:

  • 2.0.0



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

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
  LegacyFacter.log_exception(e, "Timed out after #{limit} seconds while resolving #{qualified_name}")
  nil
rescue LegacyFacter::Util::Normalization::NormalizationError => e
  LegacyFacter.log_exception(e, "Fact resolution #{qualified_name} resolved to an invalid value: #{e.message}")
  nil
rescue StandardError => e
  LegacyFacter.log_exception(e, "Error while resolving custom fact #{qualified_name}: #{e.message}")
  at_exit { exit 1 }
  raise Facter::ResolveCustomFactError
end