Class: NdrStats::Ping
- Inherits:
-
Object
- Object
- NdrStats::Ping
- Defined in:
- lib/ndr_stats/ping.rb
Overview
Ping instances make regular increments to a :ping counter, as a means of checking that a progress is up.
They can be started and stopped, as well as registered and removed centrally. Generally, use via ‘NdrStats.ping` is recommended.
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(every: 60, type:, **tags) ⇒ Ping
constructor
A new instance of Ping.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(every: 60, type:, **tags) ⇒ Ping
Returns a new instance of Ping.
38 39 40 41 42 43 |
# File 'lib/ndr_stats/ping.rb', line 38 def initialize(every: 60, type:, **) @interval = every @tags = .merge!(type: type) @thread = nil end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
36 37 38 |
# File 'lib/ndr_stats/ping.rb', line 36 def interval @interval end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
36 37 38 |
# File 'lib/ndr_stats/ping.rb', line 36 def @tags end |
Class Method Details
.list ⇒ Object
11 12 13 |
# File 'lib/ndr_stats/ping.rb', line 11 def list @list ||= [] end |
.register(**args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ndr_stats/ping.rb', line 15 def register(**args) instance = new(**args) if list.detect { |other| other. == instance. } raise ArgumentError, 'another tagged instance already exists!' else list << instance end instance.tap(&:start) end |
.remove_all ⇒ Object
27 28 29 30 |
# File 'lib/ndr_stats/ping.rb', line 27 def remove_all list.each(&:stop) list.clear end |
Instance Method Details
#running? ⇒ Boolean
62 63 64 |
# File 'lib/ndr_stats/ping.rb', line 62 def running? @thread&.alive? end |
#start ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/ndr_stats/ping.rb', line 45 def start raise 'already started!' if running? initial_ping @thread = Thread.new { ping_forever } self end |
#stop ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/ndr_stats/ping.rb', line 53 def stop return unless @thread @thread.kill @thread.join final_ping end |