Class: WSDirector::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdirector/result.rb

Overview

Handle results from all clients from the group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ Result

Returns a new instance of Result.



8
9
10
11
12
13
14
15
16
17
# File 'lib/wsdirector/result.rb', line 8

def initialize(group)
  @group = group
  @errors = Concurrent::Array.new

  @all = Concurrent::AtomicFixnum.new(0)
  @failures = Concurrent::AtomicFixnum.new(0)

  @sampling_mutex = Mutex.new
  @sampling_counter = Hash.new { |h, k| h[k] = 0 }
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/wsdirector/result.rb', line 6

def errors
  @errors
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/wsdirector/result.rb', line 6

def group
  @group
end

Instance Method Details

#failed(error_message) ⇒ Object

Called when client failed



25
26
27
28
29
# File 'lib/wsdirector/result.rb', line 25

def failed(error_message)
  errors << error_message
  all.increment
  failures.increment
end

#failures_countObject



39
40
41
# File 'lib/wsdirector/result.rb', line 39

def failures_count
  failures.value
end

#succeedObject

Called when client successfully finished it’s work



20
21
22
# File 'lib/wsdirector/result.rb', line 20

def succeed
  all.increment
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/wsdirector/result.rb', line 31

def success?
  failures.value.zero?
end

#total_countObject



35
36
37
# File 'lib/wsdirector/result.rb', line 35

def total_count
  all.value
end

#track_sample(id, max) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/wsdirector/result.rb', line 43

def track_sample(id, max)
  sampling_mutex.synchronize do
    return false if sampling_counter[id] >= max

    sampling_counter[id] += 1
    true
  end
end