Async::ContainerSourceAsyncContainerStatistics

class Statistics

Tracks various statistics relating to child instances in a container.

Definitions

def initialize

Initialize the statistics all to 0.

Implementation

def initialize
	@spawns = 0
	@restarts = 0
	@failures = 0
end

attr :spawns

How many child instances have been spawned.

Signature

attribute Integer

attr :restarts

How many child instances have been restarted.

Signature

attribute Integer

attr :failures

How many child instances have failed.

Signature

attribute Integer

def spawn!

Increment the number of spawns by 1.

Implementation

def spawn!
	@spawns += 1
end

def restart!

Increment the number of restarts by 1.

Implementation

def restart!
	@restarts += 1
end

def failure!

Increment the number of failures by 1.

Implementation

def failure!
	@failures += 1
end

def failed?

Whether there have been any failures.

Signature

returns Boolean

If the failure count is greater than 0.

Implementation

def failed?
	@failures > 0
end

def <<(other)

Append another statistics instance into this one.

Signature

parameter other Statistics

The statistics to append.

Implementation

def << other
	@spawns += other.spawns
	@restarts += other.restarts
	@failures += other.failures
end

def as_json(...)

Generate a hash representation of the statistics.

Signature

returns Hash

The statistics as a hash.

Implementation

def as_json(...)
	{
		spawns: @spawns,
		restarts: @restarts,
		failures: @failures,
	}
end

def to_json(...)

Generate a JSON representation of the statistics.

Signature

returns String

The statistics as JSON.

Implementation

def to_json(...)
	as_json.to_json(...)
end