Class: FiberAudit::Runtime::WatchdogPolicy
- Inherits:
-
Data
- Object
- Data
- FiberAudit::Runtime::WatchdogPolicy
- Defined in:
- lib/fiber_audit/runtime/watchdog_policy.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
-
#heartbeat_interval_ms ⇒ Object
readonly
Returns the value of attribute heartbeat_interval_ms.
-
#max_frames ⇒ Object
readonly
Returns the value of attribute max_frames.
-
#stall_threshold_ms ⇒ Object
readonly
Returns the value of attribute stall_threshold_ms.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #heartbeat_interval_ns ⇒ Object
-
#initialize(**values) ⇒ WatchdogPolicy
constructor
A new instance of WatchdogPolicy.
- #stall_threshold_ns ⇒ Object
- #stalled?(age_ns:) ⇒ Boolean
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
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled
7 8 9 |
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 7 def enabled @enabled end |
#heartbeat_interval_ms ⇒ Object (readonly)
Returns the value of attribute 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_frames ⇒ Object (readonly)
Returns the value of attribute max_frames
7 8 9 |
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 7 def max_frames @max_frames end |
#stall_threshold_ms ⇒ Object (readonly)
Returns the value of attribute 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
32 33 34 |
# File 'lib/fiber_audit/runtime/watchdog_policy.rb', line 32 def enabled? enabled end |
#heartbeat_interval_ns ⇒ Object
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_ns ⇒ Object
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
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 |