Module: Datadog::Workers::IntervalLoop
- Defined in:
- lib/ddtrace/workers/loop.rb
Overview
Adds looping behavior to workers, with a sleep interval between each loop.
Defined Under Namespace
Modules: PrependedMethods
Constant Summary
collapse
- BACK_OFF_RATIO =
1.2
- BACK_OFF_MAX =
5
- BASE_INTERVAL =
1
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#loop_back_off_max ⇒ Object
48
49
50
|
# File 'lib/ddtrace/workers/loop.rb', line 48
def loop_back_off_max
@loop_back_off_max ||= BACK_OFF_MAX
end
|
#loop_back_off_ratio ⇒ Object
44
45
46
|
# File 'lib/ddtrace/workers/loop.rb', line 44
def loop_back_off_ratio
@loop_back_off_ratio ||= BACK_OFF_RATIO
end
|
#loop_base_interval ⇒ Object
40
41
42
|
# File 'lib/ddtrace/workers/loop.rb', line 40
def loop_base_interval
@loop_base_interval ||= BASE_INTERVAL
end
|
Class Method Details
.included(base) ⇒ Object
10
11
12
|
# File 'lib/ddtrace/workers/loop.rb', line 10
def self.included(base)
base.send(:prepend, PrependedMethods)
end
|
Instance Method Details
#loop_back_off!(amount = nil) ⇒ Object
60
61
62
|
# File 'lib/ddtrace/workers/loop.rb', line 60
def loop_back_off!(amount = nil)
@loop_wait_time = amount || [loop_wait_time * BACK_OFF_RATIO, BACK_OFF_MAX].min
end
|
#loop_back_off? ⇒ Boolean
56
57
58
|
# File 'lib/ddtrace/workers/loop.rb', line 56
def loop_back_off?
false
end
|
#loop_wait_time ⇒ Object
52
53
54
|
# File 'lib/ddtrace/workers/loop.rb', line 52
def loop_wait_time
@loop_wait_time ||= loop_base_interval
end
|
#run_loop? ⇒ Boolean
35
36
37
38
|
# File 'lib/ddtrace/workers/loop.rb', line 35
def run_loop?
@run_loop = false unless instance_variable_defined?(:@run_loop)
@run_loop == true
end
|
#stop_loop ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/ddtrace/workers/loop.rb', line 21
def stop_loop
mutex.synchronize do
return false unless run_loop?
@run_loop = false
shutdown.signal
end
true
end
|
#work_pending? ⇒ Boolean
31
32
33
|
# File 'lib/ddtrace/workers/loop.rb', line 31
def work_pending?
run_loop?
end
|