Module: Datadog::Core::Workers::Async::Thread Private
- Defined in:
- lib/datadog/core/workers/async.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 threading behavior to workers to run tasks asynchronously.
This module is included in Polling module, and has no other direct users.
Defined Under Namespace
Modules: PrependedMethods
Constant Summary collapse
- FORK_POLICY_STOP =
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.
:stop- FORK_POLICY_RESTART =
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.
:restart- SHUTDOWN_TIMEOUT =
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
- #error ⇒ Object readonly private
- #fork_policy ⇒ Object private
- #result ⇒ Object readonly private
Class Method Summary collapse
- .included(base) ⇒ Object private
Instance Method Summary collapse
- #completed? ⇒ Boolean private
- #error? ⇒ Boolean private
- #failed? ⇒ Boolean private
- #forked? ⇒ Boolean private
- #join(timeout = nil) ⇒ Object private
- #run_async? ⇒ Boolean private
- #running? ⇒ Boolean private
- #started? ⇒ Boolean private
- #terminate ⇒ Object private
Instance Attribute Details
#error ⇒ Object (readonly)
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.
40 41 42 |
# File 'lib/datadog/core/workers/async.rb', line 40 def error @error end |
#fork_policy ⇒ 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.
102 103 104 |
# File 'lib/datadog/core/workers/async.rb', line 102 def fork_policy @fork_policy ||= FORK_POLICY_STOP end |
#result ⇒ 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.
40 41 42 |
# File 'lib/datadog/core/workers/async.rb', line 40 def result @result 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.
25 26 27 |
# File 'lib/datadog/core/workers/async.rb', line 25 def self.included(base) base.prepend(PrependedMethods) end |
Instance Method Details
#completed? ⇒ 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.
90 91 92 |
# File 'lib/datadog/core/workers/async.rb', line 90 def completed? !worker.nil? && worker.status == false && !error? end |
#error? ⇒ 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.
84 85 86 87 88 |
# File 'lib/datadog/core/workers/async.rb', line 84 def error? return false unless instance_variable_defined?(:@error) !@error.nil? end |
#failed? ⇒ 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.
94 95 96 |
# File 'lib/datadog/core/workers/async.rb', line 94 def failed? !worker.nil? && worker.status.nil? end |
#forked? ⇒ 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.
98 99 100 |
# File 'lib/datadog/core/workers/async.rb', line 98 def forked? !pid.nil? && pid != Process.pid end |
#join(timeout = nil) ⇒ 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.
47 48 49 50 51 |
# File 'lib/datadog/core/workers/async.rb', line 47 def join(timeout = nil) return true unless running? !worker.join(timeout).nil? end |
#run_async? ⇒ 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.
70 71 72 73 74 |
# File 'lib/datadog/core/workers/async.rb', line 70 def run_async? return false unless instance_variable_defined?(:@run_async) @run_async == true end |
#running? ⇒ 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.
80 81 82 |
# File 'lib/datadog/core/workers/async.rb', line 80 def running? !worker.nil? && worker.alive? end |
#started? ⇒ 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.
76 77 78 |
# File 'lib/datadog/core/workers/async.rb', line 76 def started? !(worker.nil? || forked?) end |
#terminate ⇒ 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/datadog/core/workers/async.rb', line 53 def terminate return false unless running? @run_async = false Datadog.logger.debug { "Forcibly terminating worker thread for: #{self}" } worker.terminate # Wait for the worker thread to end begin Timeout.timeout(SHUTDOWN_TIMEOUT) do worker.join end rescue Timeout::Error Datadog.logger.debug { "Worker thread did not end after #{SHUTDOWN_TIMEOUT} seconds: #{self}" } end true end |