Module: RFacter::Core::Resolvable Private
- Included in:
- Aggregate, Util::Resolution
- Defined in:
- lib/rfacter/core/resolvable.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
The resolvable mixin defines behavior for evaluating and returning fact resolutions.
Classes including this mixin should implement at #name method describing the value being resolved and a #resolve_value that actually executes the code to resolve the value.
Instance Attribute Summary collapse
-
#timeout ⇒ Integer
The timeout, in seconds, for evaluating this resolution.
Instance Method Summary collapse
-
#flush ⇒ Object
private
flush executes the block, if any, stored by the #on_flush method.
-
#limit ⇒ Numeric
private
Return the timeout period for resolving a value.
-
#on_flush(&block) ⇒ Object
on_flush accepts a block and executes the block when the resolution’s value is flushed.
- #value ⇒ Object private
Instance Attribute Details
#timeout ⇒ Integer
The timeout, in seconds, for evaluating this resolution.
20 21 22 |
# File 'lib/rfacter/core/resolvable.rb', line 20 def timeout @timeout end |
Instance Method Details
#flush ⇒ Object
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
58 59 60 |
# File 'lib/rfacter/core/resolvable.rb', line 58 def flush @on_flush_block.call if @on_flush_block end |
#limit ⇒ Numeric
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.
Return the timeout period for resolving a value. (see #timeout)
25 26 27 28 29 30 31 |
# File 'lib/rfacter/core/resolvable.rb', line 25 def limit # requiring 'timeout' stdlib class causes Object#timeout to be defined # which delegates to Timeout.timeout. This method may potentially overwrite # the #timeout attr_reader on this class, so we define #limit to avoid # conflicts. @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.
48 49 50 |
# File 'lib/rfacter/core/resolvable.rb', line 48 def on_flush(&block) @on_flush_block = block end |
#value ⇒ Object
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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rfacter/core/resolvable.rb', line 62 def value result = nil with_timing do Timeout.timeout(limit) do result = resolve_value end end RFacter::Util::Normalization.normalize(result) rescue Timeout::Error => detail logger.log_exception(detail, "Timed out after #{limit} seconds while resolving #{qualified_name}") return nil rescue RFacter::Util::Normalization::NormalizationError => detail logger.log_exception(detail, "Fact resolution #{qualified_name} resolved to an invalid value: #{detail.}") return nil rescue => detail logger.log_exception(detail, "Could not retrieve #{qualified_name}: #{detail.}") return nil end |