Class: XRay::LeadPoller

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/aws-xray-sdk/sampling/lead_poller.rb

Overview

The poller to report the current statistics of all sampling rules and retrieve the new allocated sampling quota and TTL from X-Ray service. It also controls the rule poller.

Constant Summary collapse

@@interval =

working frequency of the lead poller

10
@@rule_interval =

5 minutes on polling rules

5 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Constructor Details

#initialize(cache) ⇒ LeadPoller

Returns a new instance of LeadPoller.



16
17
18
19
20
21
# File 'lib/aws-xray-sdk/sampling/lead_poller.rb', line 16

def initialize(cache)
  @cache = cache
  @connector = ServiceConnector.new
  @rule_poller = RulePoller.new cache: @cache, connector: @connector
  @rule_poller_elapsed = 0
end

Instance Attribute Details

#connectorObject (readonly)

Returns the value of attribute connector.



12
13
14
# File 'lib/aws-xray-sdk/sampling/lead_poller.rb', line 12

def connector
  @connector
end

Instance Method Details

#startObject



23
24
25
26
# File 'lib/aws-xray-sdk/sampling/lead_poller.rb', line 23

def start
  @rule_poller.run
  Thread.new { worker }
end

#workerObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aws-xray-sdk/sampling/lead_poller.rb', line 28

def worker
  loop do
    sleep_time = @@interval + rand
    sleep sleep_time
    @rule_poller_elapsed += sleep_time
    refresh_cache
    if @rule_poller_elapsed >= @@rule_interval
      @rule_poller.run
      @rule_poller_elapsed = 0
    end
  end
end