Class: Datadog::Core::Cloudwise::AppRegistrationWorker

Inherits:
Worker
  • Object
show all
Includes:
Workers::Polling
Defined in:
lib/datadog/core/cloudwise/app_registration_worker.rb

Overview

Worker that registers application every 3 minutes 应用注册失败不影响数据采集

Constant Summary collapse

DEFAULT_INTERVAL =

3 minutes interval

180
CODE_SUCCESS =

成功的状态码

1000

Constants included from Workers::Polling

Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Worker

#task

Instance Method Summary collapse

Methods included from Workers::Polling

#enabled=, #enabled?, included, #stop

Constructor Details

#initialize(client:, logger:, probe_state:, **options) ⇒ AppRegistrationWorker

Returns a new instance of AppRegistrationWorker.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datadog/core/cloudwise/app_registration_worker.rb', line 22

def initialize(client:, logger:, probe_state:, **options)
  @client = client
  @logger = logger
  @probe_state = probe_state
  @registration_successful = false

  # Workers::Async::Thread settings
  self.fork_policy = options.fetch(:fork_policy, Workers::Async::Thread::FORK_POLICY_STOP)

  # Workers::IntervalLoop settings
  self.loop_base_interval = options.fetch(:interval, DEFAULT_INTERVAL)

  self.enabled = options.fetch(:enabled, true)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/datadog/core/cloudwise/app_registration_worker.rb', line 20

def client
  @client
end

Instance Method Details

#performObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/datadog/core/cloudwise/app_registration_worker.rb', line 37

def perform
  # Wait for Host ID to be generated
  unless client.
    Cloudwise.log_debug { 'Cloudwise: Waiting for Host ID generation before application registration' }
    return true
  end

  Cloudwise.log_debug { 'Cloudwise: Registering application' }

  result = client.register_application

  process_registration_result(result)

  true
rescue => e
  Cloudwise.log_error { "Cloudwise: Application registration worker error: #{e.class.name} #{e.message}" }
  @probe_state.mark_app_unregistered!
  true # Continue running
end

#registered?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/datadog/core/cloudwise/app_registration_worker.rb', line 57

def registered?
  @registration_successful
end

#startObject

Public method to start the worker



62
63
64
65
66
67
# File 'lib/datadog/core/cloudwise/app_registration_worker.rb', line 62

def start
  return false if !enabled? || started?

  # Start the async worker thread
  perform
end