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
- MUTEX_INIT =
This single shared mutex is used to avoid concurrency issues during the initialization of per-instance lazy-initialized mutexes.
Mutex.new
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#loop_back_off_max ⇒ Object
68
69
70
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 68
def loop_back_off_max
@loop_back_off_max ||= BACK_OFF_MAX
end
|
#loop_back_off_ratio ⇒ Object
64
65
66
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 64
def loop_back_off_ratio
@loop_back_off_ratio ||= BACK_OFF_RATIO
end
|
#loop_base_interval ⇒ Object
60
61
62
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 60
def loop_base_interval
@loop_base_interval ||= BASE_INTERVAL
end
|
Class Method Details
.included(base) ⇒ Object
17
18
19
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 17
def self.included(base)
base.prepend(PrependedMethods)
end
|
Instance Method Details
#loop_back_off! ⇒ Object
80
81
82
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 80
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.
88
89
90
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 88
def loop_wait_before_first_iteration?
false
end
|
#loop_wait_time ⇒ Object
72
73
74
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 72
def loop_wait_time
@loop_wait_time ||= loop_base_interval
end
|
#loop_wait_time=(value) ⇒ Object
76
77
78
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 76
def loop_wait_time=(value)
@loop_wait_time = value
end
|
#run_loop? ⇒ Boolean
54
55
56
57
58
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 54
def run_loop?
return false unless instance_variable_defined?(:@run_loop)
@run_loop == true
end
|
#stop_loop ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 39
def stop_loop
mutex.synchronize do
return false unless run_loop?
@run_loop = false
shutdown.signal
end
true
end
|
#work_pending? ⇒ Boolean
50
51
52
|
# File 'lib/datadog/core/workers/interval_loop.rb', line 50
def work_pending?
run_loop?
end
|