Class: Expeditor::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/expeditor/bucket.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Bucket

Returns a new instance of Bucket.



5
6
7
8
9
10
11
12
13
14
# File 'lib/expeditor/bucket.rb', line 5

def initialize(opts = {})
  @mutex = Mutex.new
  @current_index = 0
  @size = opts.fetch(:size, 10)
  @per_time = opts.fetch(:per, 1)
  @current_start = Time.now
  @statuses = [].fill(0..(@size - 1)) do
    Expeditor::Status.new
  end
end

Instance Method Details

#currentObject



46
47
48
49
50
51
# File 'lib/expeditor/bucket.rb', line 46

def current
  @mutex.synchronize do
    update
    @statuses[@current_index]
  end
end

#increment(type) ⇒ Object



16
17
18
19
20
21
# File 'lib/expeditor/bucket.rb', line 16

def increment(type)
  @mutex.synchronize do
    update
    @statuses[@current_index].increment type
  end
end

#totalObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/expeditor/bucket.rb', line 23

def total
  acc = @mutex.synchronize do
    update
    @statuses.inject([0, 0, 0, 0, 0, 0]) do |acc, s|
      acc[0] += s.success
      acc[1] += s.failure
      acc[2] += s.rejection
      acc[3] += s.timeout
      acc[4] += s.break
      acc[5] += s.dependency
      acc
    end
  end
  status = Expeditor::Status.new
  status.success = acc[0]
  status.failure = acc[1]
  status.rejection = acc[2]
  status.timeout = acc[3]
  status.break = acc[4]
  status.dependency = acc[5]
  status
end