Class: Chronos::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/chronos/agent.rb

Overview

Runtime composition root for the framework-independent Chronos agent.

Examples:

agent.notify(RuntimeError.new("failed"))

Constant Summary collapse

DEFAULT_FLUSH_TIMEOUT =
5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ Agent

Returns a new instance of Agent.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/chronos/agent.rb', line 19

def initialize(config, options = {})
  @config = config
  @logger = options[:logger] || Internal::SafeLogger.new(config.logger)
  @transport = options[:transport] || Adapters::NetHttpTransport.new(config, @logger)
  unless Ports::Transport.compatible?(@transport)
    raise ArgumentError, "transport does not implement the Chronos transport port"
  end
  pipeline_options = {}
  pipeline_options[:queue] = options[:queue] if options[:queue]
  pipeline_options[:worker_pool] = options[:worker_pool] if options[:worker_pool]
  @delivery_pipeline = options[:delivery_pipeline] || Application::DeliveryPipeline.new(
    config,
    @transport,
    @logger,
    pipeline_options
  )
  @capture = options[:capture] || Application::CaptureException.new(config, @delivery_pipeline, @logger)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/chronos/agent.rb', line 17

def config
  @config
end

Instance Method Details

#close(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object



53
54
55
56
57
58
# File 'lib/chronos/agent.rb', line 53

def close(timeout = DEFAULT_FLUSH_TIMEOUT)
  @delivery_pipeline.close(timeout)
rescue StandardError => error
  @logger.warn("Chronos close failed: #{error.class}")
  false
end

#diagnosticsObject



60
61
62
63
# File 'lib/chronos/agent.rb', line 60

def diagnostics
  details = @delivery_pipeline.diagnostics
  details[:queue].merge(details)
end

#flush(timeout = DEFAULT_FLUSH_TIMEOUT) ⇒ Object



46
47
48
49
50
51
# File 'lib/chronos/agent.rb', line 46

def flush(timeout = DEFAULT_FLUSH_TIMEOUT)
  @delivery_pipeline.flush(timeout)
rescue StandardError => error
  @logger.warn("Chronos flush failed: #{error.class}")
  false
end

#notify(exception, context = {}) ⇒ Object



38
39
40
# File 'lib/chronos/agent.rb', line 38

def notify(exception, context = {})
  @capture.call(exception, context)
end

#notify_sync(exception, context = {}) ⇒ Object



42
43
44
# File 'lib/chronos/agent.rb', line 42

def notify_sync(exception, context = {})
  @capture.call_sync(exception, context)
end