Module: Datadog::Core::Workers::IntervalLoop Private
- Defined in:
- lib/datadog/core/workers/interval_loop.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Adds looping behavior to workers, with a sleep interval between each loop.
This module is included in Polling module, and has no other direct users.
Defined Under Namespace
Modules: PrependedMethods
Constant Summary collapse
- BACK_OFF_RATIO =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1.2- BACK_OFF_MAX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
5- BASE_INTERVAL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1- MUTEX_INIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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
- #loop_back_off_max ⇒ Object readonly private
- #loop_back_off_ratio ⇒ Object readonly private
- #loop_base_interval ⇒ Object readonly private
Class Method Summary collapse
- .included(base) ⇒ Object private
Instance Method Summary collapse
- #loop_back_off! ⇒ Object private
-
#loop_wait_before_first_iteration? ⇒ Boolean
private
Should perform_loop just straight into work, or start by waiting?.
- #loop_wait_time ⇒ Object private
- #loop_wait_time=(value) ⇒ Object private
- #run_loop? ⇒ Boolean private
- #stop_loop ⇒ Object private
-
#work_pending? ⇒ Boolean
private
TODO This overwrites Queue’s
work_pending?method with an implementation that, to me, is at leat questionable semantically: the Queue’s idea of pending work is if the buffer is not empty, but this module says that work is pending if the work processing loop is scheduled to run (in other words, as long as the background thread is running, there is always pending work).
Instance Attribute Details
#loop_back_off_max ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 97 def loop_back_off_max @loop_back_off_max ||= BACK_OFF_MAX end |
#loop_back_off_ratio ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 93 def loop_back_off_ratio @loop_back_off_ratio ||= BACK_OFF_RATIO end |
#loop_base_interval ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 89 def loop_base_interval @loop_base_interval ||= BASE_INTERVAL end |
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 22 def self.included(base) base.prepend(PrependedMethods) end |
Instance Method Details
#loop_back_off! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 109 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
117 118 119 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 117 def loop_wait_before_first_iteration? false end |
#loop_wait_time ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 101 def loop_wait_time @loop_wait_time ||= loop_base_interval end |
#loop_wait_time=(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 105 def loop_wait_time=(value) @loop_wait_time = value end |
#run_loop? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 83 def run_loop? return false unless instance_variable_defined?(:@run_loop) @run_loop == true end |
#stop_loop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 44 def stop_loop mutex.synchronize do # Do not call run_loop? from this method to see if the loop # is running, because @run_loop is normally initialized by # the background thread and if the stop is requested right # after the worker starts, the background thread may be created # (and scheduled) but hasn't run yet, thus skipping the # write to @run_loop here would leave the thread running forever. @run_loop = false # It is possible that we don't need to signal shutdown if # @run_loop was not initialized (i.e. we changed it from not # defined to false above). But let's be safe and signal the # shutdown anyway, I don't see what harm it can cause. shutdown.signal end # Previously, this method would return false (and do nothing) # if the worker was not running the loop. However, this was racy - # see https://github.com/DataDog/ruby-guild/issues/279. # stop_loop now always sets the state to "stop requested" and, # correspondingly, always returns true. # # There is some test code that returns false when mocking this # method - most likely this method should be treated as a void one # and the caller should assume that the stop was always requested. true end |
#work_pending? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO This overwrites Queue’s work_pending? method with an implementation that, to me, is at leat questionable semantically: the Queue’s idea of pending work is if the buffer is not empty, but this module says that work is pending if the work processing loop is scheduled to run (in other words, as long as the background thread is running, there is always pending work).
79 80 81 |
# File 'lib/datadog/core/workers/interval_loop.rb', line 79 def work_pending? run_loop? end |