Module: Datadog::Core::Workers::IntervalLoop
- Defined in:
- lib/datadog/core/workers/interval_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
53
54
55
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 53
def loop_back_off_max
@loop_back_off_max ||= BACK_OFF_MAX
end
|
#loop_back_off_ratio ⇒ Object
49
50
51
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 49
def loop_back_off_ratio
@loop_back_off_ratio ||= BACK_OFF_RATIO
end
|
#loop_base_interval ⇒ Object
45
46
47
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 45
def loop_base_interval
@loop_base_interval ||= BASE_INTERVAL
end
|
Class Method Details
.included(base) ⇒ Object
13
14
15
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 13
def self.included(base)
base.prepend(PrependedMethods)
end
|
Instance Method Details
#loop_back_off! ⇒ Object
65
66
67
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 65
def loop_back_off!
self.loop_wait_time = [loop_wait_time * BACK_OFF_RATIO, BACK_OFF_MAX].min
end
|
#loop_wait_before_first_iteration? ⇒ Boolean
Should perform_loop just straight into work, or start by waiting?
The use case is if we want to report some information (like profiles) from time to time, we may not want to report empty/zero/some residual value immediately when the worker starts.
73
74
75
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 73
def loop_wait_before_first_iteration?
false
end
|
#loop_wait_time ⇒ Object
57
58
59
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 57
def loop_wait_time
@loop_wait_time ||= loop_base_interval
end
|
#loop_wait_time=(value) ⇒ Object
61
62
63
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 61
def loop_wait_time=(value)
@loop_wait_time = value
end
|
#run_loop? ⇒ Boolean
39
40
41
42
43
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 39
def run_loop?
return false unless instance_variable_defined?(:@run_loop)
@run_loop == true
end
|
#stop_loop ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 24
def stop_loop
mutex.synchronize do
return false unless run_loop?
@run_loop = false
shutdown.signal
end
true
end
|
#work_pending? ⇒ Boolean
35
36
37
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 35
def work_pending?
run_loop?
end
|