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

#errorObject (readonly)

Returns the value of attribute error.



25
26
27
# File 'lib/ddtrace/workers/async.rb', line 25

def error
  @error
end

#fork_policyObject



74
75
76
# File 'lib/ddtrace/workers/async.rb', line 74

def fork_policy
  @fork_policy ||= FORK_POLICY_STOP
end

#resultObject

Returns the value of attribute result.



25
26
27
# File 'lib/ddtrace/workers/async.rb', line 25

def result
  @result
end

Class Method Details

.included(base) ⇒ Object



14
15
16
# File 'lib/ddtrace/workers/async.rb', line 14

def self.included(base)
  base.send(:prepend, PrependedMethods)
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/ddtrace/workers/async.rb', line 62

def completed?
  !worker.nil? && worker.status == false && !error?
end

#error?Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/ddtrace/workers/async.rb', line 57

def error?
  return false unless instance_variable_defined?(:@error)
  !@error.nil?
end

#failed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/ddtrace/workers/async.rb', line 66

def failed?
  !worker.nil? && worker.status.nil?
end

#forked?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ddtrace/workers/async.rb', line 70

def forked?
  !pid.nil? && pid != Process.pid
end

#join(timeout = nil) ⇒ Object



32
33
34
35
# File 'lib/ddtrace/workers/async.rb', line 32

def join(timeout = nil)
  return true unless running?
  !worker.join(timeout).nil?
end

#run_async?Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/ddtrace/workers/async.rb', line 44

def run_async?
  return false unless instance_variable_defined?(:@run_async)
  @run_async == true
end

#running?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ddtrace/workers/async.rb', line 53

def running?
  !worker.nil? && worker.alive?
end

#started?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ddtrace/workers/async.rb', line 49

def started?
  !(worker.nil? || forked?)
end

#terminateObject



37
38
39
40
41
42
# File 'lib/ddtrace/workers/async.rb', line 37

def terminate
  return false unless running?
  @run_async = false
  worker.terminate
  true
end