Class: FiberAudit::Runtime::WatchdogPolicy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**values) ⇒ WatchdogPolicy

Returns a new instance of WatchdogPolicy.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 13

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

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

  limits = WatchdogPolicy::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/watchdog_policy.rb', line 7

def enabled
  @enabled
end

#heartbeat_interval_msObject (readonly)

Returns the value of attribute heartbeat_interval_ms

Returns:

  • (Object)

    the current value of heartbeat_interval_ms



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

def heartbeat_interval_ms
  @heartbeat_interval_ms
end

#max_framesObject (readonly)

Returns the value of attribute max_frames

Returns:

  • (Object)

    the current value of max_frames



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

def max_frames
  @max_frames
end

#stall_threshold_msObject (readonly)

Returns the value of attribute stall_threshold_ms

Returns:

  • (Object)

    the current value of stall_threshold_ms



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

def stall_threshold_ms
  @stall_threshold_ms
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 32

def enabled?
  enabled
end

#heartbeat_interval_nsObject



36
37
38
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 36

def heartbeat_interval_ns
  heartbeat_interval_ms * WatchdogPolicy::NANOSECONDS_PER_MILLISECOND
end

#stall_threshold_nsObject



40
41
42
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 40

def stall_threshold_ns
  stall_threshold_ms * WatchdogPolicy::NANOSECONDS_PER_MILLISECOND
end

#stalled?(age_ns:) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 44

def stalled?(age_ns:)
  age = Validation.integer(age_ns, 'heartbeat age')
  age > stall_threshold_ns
end