Class: Expeditor::Service
- Inherits:
-
Object
- Object
- Expeditor::Service
show all
- Defined in:
- lib/expeditor/service.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Service
Returns a new instance of Service.
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/expeditor/service.rb', line 8
def initialize(opts = {})
@executor = opts.fetch(:executor) { Concurrent::ThreadPoolExecutor.new }
@threshold = opts.fetch(:threshold, 0.5) @non_break_count = opts.fetch(:non_break_count, 100) @sleep = opts.fetch(:sleep, 1)
@bucket_opts = {
size: 10,
per: opts.fetch(:period, 10).to_f / 10
}
reset_status!
@fallback_enabled = true
end
|
Instance Attribute Details
#executor ⇒ Object
Returns the value of attribute executor.
5
6
7
|
# File 'lib/expeditor/service.rb', line 5
def executor
@executor
end
|
#fallback_enabled ⇒ Object
Returns the value of attribute fallback_enabled.
6
7
8
|
# File 'lib/expeditor/service.rb', line 6
def fallback_enabled
@fallback_enabled
end
|
Instance Method Details
#break ⇒ Object
37
38
39
|
# File 'lib/expeditor/service.rb', line 37
def break
@bucket.increment :break
end
|
#current_status ⇒ Object
73
74
75
|
# File 'lib/expeditor/service.rb', line 73
def current_status
@bucket.current
end
|
#dependency ⇒ Object
41
42
43
|
# File 'lib/expeditor/service.rb', line 41
def dependency
@bucket.increment :dependency
end
|
#failure ⇒ Object
25
26
27
|
# File 'lib/expeditor/service.rb', line 25
def failure
@bucket.increment :failure
end
|
#fallback_enabled? ⇒ Boolean
45
46
47
|
# File 'lib/expeditor/service.rb', line 45
def fallback_enabled?
!!fallback_enabled
end
|
#open? ⇒ Boolean
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/expeditor/service.rb', line 50
def open?
if @breaking
if Time.now - @break_start > @sleep
@breaking = false
@break_start = nil
else
return true
end
end
open = calc_open
if open
@breaking = true
@break_start = Time.now
end
open
end
|
#rejection ⇒ Object
29
30
31
|
# File 'lib/expeditor/service.rb', line 29
def rejection
@bucket.increment :rejection
end
|
#reset_status! ⇒ Object
77
78
79
80
81
|
# File 'lib/expeditor/service.rb', line 77
def reset_status!
@bucket = Expeditor::Bucket.new(@bucket_opts)
@breaking = false
@break_start = nil
end
|
#shutdown ⇒ Object
shutdown thread pool after shutdown, if you create thread, RejectedExecutionError is raised.
69
70
71
|
# File 'lib/expeditor/service.rb', line 69
def shutdown
@executor.shutdown
end
|
#success ⇒ Object
21
22
23
|
# File 'lib/expeditor/service.rb', line 21
def success
@bucket.increment :success
end
|
#timeout ⇒ Object
33
34
35
|
# File 'lib/expeditor/service.rb', line 33
def timeout
@bucket.increment :timeout
end
|