Class: FiberAudit::Runtime::OperationLivenessPolicy

Inherits:
Data
  • Object
show all
Defined in:
lib/fiber_audit/runtime/operation_liveness_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**values) ⇒ OperationLivenessPolicy

Returns a new instance of OperationLivenessPolicy.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 8

def initialize(**values)
  unknown = values.keys - OperationLivenessPolicy::DEFAULTS.keys
  raise RuntimeContractError, "unknown operation liveness policy field: #{unknown.first}" unless unknown.empty?

  fields = OperationLivenessPolicy::DEFAULTS.merge(values)
  raise RuntimeContractError, 'enabled must be a Boolean' unless [true, false].include?(fields[:enabled])

  limits = OperationLivenessPolicy::LIMITS.to_h do |name, range|
    value = fields.fetch(name)
    unless value.is_a?(Integer) && range.cover?(value)
      raise RuntimeContractError, "#{name} must be an Integer in #{range}"
    end

    [name, value]
  end
  super(enabled: fields[:enabled], **limits)
end

Instance Attribute Details

#enabledObject (readonly)

Returns the value of attribute enabled

Returns:

  • (Object)

    the current value of enabled



7
8
9
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 7

def enabled
  @enabled
end

#long_active_threshold_msObject (readonly)

Returns the value of attribute long_active_threshold_ms

Returns:

  • (Object)

    the current value of long_active_threshold_ms



7
8
9
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 7

def long_active_threshold_ms
  @long_active_threshold_ms
end

#poll_interval_msObject (readonly)

Returns the value of attribute poll_interval_ms

Returns:

  • (Object)

    the current value of poll_interval_ms



7
8
9
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 7

def poll_interval_ms
  @poll_interval_ms
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


26
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 26

def enabled? = enabled

#long_active?(age_ns:) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 30

def long_active?(age_ns:)
  Validation.integer(age_ns, 'active operation age') > long_active_threshold_ns
end

#long_active_threshold_nsObject



28
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 28

def long_active_threshold_ns = long_active_threshold_ms * OperationLivenessPolicy::NANOSECONDS_PER_MILLISECOND

#poll_interval_nsObject



27
# File 'lib/fiber_audit/runtime/operation_liveness_policy.rb', line 27

def poll_interval_ns = poll_interval_ms * OperationLivenessPolicy::NANOSECONDS_PER_MILLISECOND