Class: Async::Container::Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/statistics.rb

Overview

Tracks various statistics relating to child instances in a container.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatistics

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

#failuresObject (readonly)

How many child instances have failed.



29
30
31
# File 'lib/async/container/statistics.rb', line 29

def failures
  @failures
end

#restartsObject (readonly)

How many child instances have been restarted.



25
26
27
# File 'lib/async/container/statistics.rb', line 25

def restarts
  @restarts
end

#spawnsObject (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_jsonObject

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.

Returns:

  • (Boolean)


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_jsonObject

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