Class: Async::Container::Statistics
- Inherits:
-
Object
- Object
- Async::Container::Statistics
- Defined in:
- lib/async/container/statistics.rb
Overview
Tracks various statistics relating to child instances in a container.
Instance Attribute Summary collapse
-
#failures ⇒ Object
readonly
How many child instances have failed.
-
#restarts ⇒ Object
readonly
How many child instances have been restarted.
-
#spawns ⇒ Object
readonly
How many child instances have been spawned.
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Append another statistics instance into this one.
-
#as_json ⇒ Object
Generate a hash representation of the statistics.
-
#failed? ⇒ Boolean
Whether there have been any failures.
-
#failure! ⇒ Object
Increment the number of failures by 1.
-
#initialize ⇒ Statistics
constructor
Initialize the statistics all to 0.
-
#restart! ⇒ Object
Increment the number of restarts by 1.
-
#spawn! ⇒ Object
Increment the number of spawns by 1.
-
#to_json ⇒ Object
Generate a JSON representation of the statistics.
Constructor Details
#initialize ⇒ Statistics
Initialize the statistics all to 0.
13 14 15 16 17 |
# File 'lib/async/container/statistics.rb', line 13 def initialize @spawns = 0 @restarts = 0 @failures = 0 end |
Instance Attribute Details
#failures ⇒ Object (readonly)
How many child instances have failed.
29 30 31 |
# File 'lib/async/container/statistics.rb', line 29 def failures @failures end |
#restarts ⇒ Object (readonly)
How many child instances have been restarted.
25 26 27 |
# File 'lib/async/container/statistics.rb', line 25 def restarts @restarts end |
#spawns ⇒ Object (readonly)
How many child instances have been spawned.
21 22 23 |
# File 'lib/async/container/statistics.rb', line 21 def spawns @spawns end |
Instance Method Details
#<<(other) ⇒ Object
Append another statistics instance into this one.
54 55 56 57 58 |
# File 'lib/async/container/statistics.rb', line 54 def << other @spawns += other.spawns @restarts += other.restarts @failures += other.failures end |
#as_json ⇒ Object
Generate a hash representation of the statistics.
63 64 65 66 67 68 69 |
# File 'lib/async/container/statistics.rb', line 63 def as_json(...) { spawns: @spawns, restarts: @restarts, failures: @failures, } end |
#failed? ⇒ Boolean
Whether there have been any failures.
48 49 50 |
# File 'lib/async/container/statistics.rb', line 48 def failed? @failures > 0 end |
#failure! ⇒ Object
Increment the number of failures by 1.
42 43 44 |
# File 'lib/async/container/statistics.rb', line 42 def failure! @failures += 1 end |
#restart! ⇒ Object
Increment the number of restarts by 1.
37 38 39 |
# File 'lib/async/container/statistics.rb', line 37 def restart! @restarts += 1 end |
#spawn! ⇒ Object
Increment the number of spawns by 1.
32 33 34 |
# File 'lib/async/container/statistics.rb', line 32 def spawn! @spawns += 1 end |
#to_json ⇒ Object
Generate a JSON representation of the statistics.
74 75 76 |
# File 'lib/async/container/statistics.rb', line 74 def to_json(...) as_json.to_json(...) end |