Module: Datadog::Workers::Async::Thread
  
  
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/ddtrace/workers/async.rb
 
  
  
 
Overview
  
    Adds threading behavior to workers
to run tasks asynchronously.
rubocop:disable Metrics/ModuleLength
   
 
  
Defined Under Namespace
  
    
      Modules: PrependedMethods
    
  
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - FORK_POLICY_STOP =
          
        
 
        :stop
 
      
        - FORK_POLICY_RESTART =
          
        
 
        :restart
 
      
        - SHUTDOWN_TIMEOUT =
          
        
 
        1
 
      
    
  
  Instance Attribute Summary collapse
  
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
  
  
    Instance Attribute Details
    
      
      
      
  
  
    #error  ⇒ Object  
  
  
  
  
    Returns the value of attribute error.
   
 
  
  
    
      
26
27
28 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 26
def error
  @error
end 
     | 
  
 
    
      
      
      
  
  
    #fork_policy  ⇒ Object 
  
  
  
  
    
      
80
81
82 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 80
def fork_policy
  @fork_policy ||= FORK_POLICY_STOP
end 
     | 
  
 
    
      
      
      
  
  
    #result  ⇒ Object 
  
  
  
  
    Returns the value of attribute result.
   
 
  
  
    
      
26
27
28 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 26
def result
  @result
end 
     | 
  
 
    
   
  
    Class Method Details
    
      
  
  
    .included(base)  ⇒ Object 
  
  
  
  
    
      
15
16
17 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 15
def self.included(base)
  base.prepend(PrependedMethods)
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #completed?  ⇒ Boolean 
  
  
  
  
    
      
68
69
70 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 68
def completed?
  !worker.nil? && worker.status == false && !error?
end 
     | 
  
 
    
      
  
  
    #error?  ⇒ Boolean 
  
  
  
  
    
      
62
63
64
65
66 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 62
def error?
  return false unless instance_variable_defined?(:@error)
  !@error.nil?
end 
     | 
  
 
    
      
  
  
    #failed?  ⇒ Boolean 
  
  
  
  
    
      
72
73
74 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 72
def failed?
  !worker.nil? && worker.status.nil?
end 
     | 
  
 
    
      
  
  
    #forked?  ⇒ Boolean 
  
  
  
  
    
      
76
77
78 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 76
def forked?
  !pid.nil? && pid != Process.pid
end 
     | 
  
 
    
      
  
  
    #join(timeout = nil)  ⇒ Object 
  
  
  
  
    
      
33
34
35
36
37 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 33
def join(timeout = nil)
  return true unless running?
  !worker.join(timeout).nil?
end 
     | 
  
 
    
      
  
  
    #run_async?  ⇒ Boolean 
  
  
  
  
    
      
48
49
50
51
52 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 48
def run_async?
  return false unless instance_variable_defined?(:@run_async)
  @run_async == true
end 
     | 
  
 
    
      
  
  
    #running?  ⇒ Boolean 
  
  
  
  
    
      
58
59
60 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 58
def running?
  !worker.nil? && worker.alive?
end 
     | 
  
 
    
      
  
  
    #started?  ⇒ Boolean 
  
  
  
  
    
      
54
55
56 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 54
def started?
  !(worker.nil? || forked?)
end 
     | 
  
 
    
      
  
  
    #terminate  ⇒ Object 
  
  
  
  
    
      
39
40
41
42
43
44
45
46 
     | 
    
      # File 'lib/ddtrace/workers/async.rb', line 39
def terminate
  return false unless running?
  @run_async = false
  Datadog.logger.debug { "Forcibly terminating worker thread for: #{self}" }
  worker.terminate
  true
end
     |