Class: Datadog::Core::Cloudwise::HeartbeatWorker
- Includes:
- Workers::Polling
- Defined in:
- lib/datadog/core/cloudwise/heartbeat_worker.rb
Overview
Worker that sends heartbeat every 30 seconds with retry mechanism 心跳失败 3 次后标记为无心跳,数据不采集
Constant Summary collapse
- DEFAULT_INTERVAL =
30 seconds interval
30- RETRY_INTERVAL =
Retry interval: 30 seconds
30- MAX_RETRIES =
Max retries: 3 times
3- CODE_SUCCESS =
成功的状态码
1000
Constants included from Workers::Polling
Workers::Polling::DEFAULT_SHUTDOWN_TIMEOUT
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Attributes inherited from Worker
Instance Method Summary collapse
-
#initialize(client:, logger:, probe_state:, **options) ⇒ HeartbeatWorker
constructor
A new instance of HeartbeatWorker.
- #perform ⇒ Object
-
#start ⇒ Object
Public method to start the worker.
Methods included from Workers::Polling
#enabled=, #enabled?, included, #stop
Constructor Details
#initialize(client:, logger:, probe_state:, **options) ⇒ HeartbeatWorker
Returns a new instance of HeartbeatWorker.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/datadog/core/cloudwise/heartbeat_worker.rb', line 26 def initialize(client:, logger:, probe_state:, **) @client = client @logger = logger @probe_state = probe_state @failure_count = 0 # Workers::Async::Thread settings self.fork_policy = .fetch(:fork_policy, Workers::Async::Thread::FORK_POLICY_STOP) # Workers::IntervalLoop settings self.loop_base_interval = .fetch(:interval, DEFAULT_INTERVAL) self.enabled = .fetch(:enabled, true) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
24 25 26 |
# File 'lib/datadog/core/cloudwise/heartbeat_worker.rb', line 24 def client @client end |
Instance Method Details
#perform ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/datadog/core/cloudwise/heartbeat_worker.rb', line 41 def perform # Wait for Host ID to be generated unless client.account_id Cloudwise.log_debug { 'Cloudwise: Waiting for Host ID generation before heartbeat' } return true end Cloudwise.log_debug { 'Cloudwise: Sending heartbeat' } result = send_heartbeat_with_retry process_heartbeat_result(result) true rescue => e Cloudwise.log_error { "Cloudwise: Heartbeat worker error: #{e.class.name} #{e.message}" } handle_heartbeat_failure true # Continue running end |
#start ⇒ Object
Public method to start the worker
62 63 64 65 66 67 |
# File 'lib/datadog/core/cloudwise/heartbeat_worker.rb', line 62 def start return false if !enabled? || started? # Start the async worker thread perform end |