Class: Prefab::LogPathCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/prefab/log_path_collector.rb

Constant Summary collapse

INCREMENT =
->(count) { (count || 0) + 1 }
SEVERITY_KEY =
{
  ::Logger::DEBUG => 'debugs',
  ::Logger::INFO => 'infos',
  ::Logger::WARN => 'warns',
  ::Logger::ERROR => 'errors',
  ::Logger::FATAL => 'fatals'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client:, max_paths:, sync_interval:) ⇒ LogPathCollector

Returns a new instance of LogPathCollector.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prefab/log_path_collector.rb', line 15

def initialize(client:, max_paths:, sync_interval:)
  @max_paths = max_paths
  @sync_interval = sync_interval
  @client = client
  @start_at = now

  @pool = Concurrent::ThreadPoolExecutor.new(
    fallback_policy: :discard,
    max_queue: 5,
    max_threads: 4,
    min_threads: 1,
    name: 'prefab-log-paths'
  )

  @paths = Concurrent::Map.new

  start_periodic_sync
end

Instance Method Details

#push(path, severity) ⇒ Object



34
35
36
37
38
# File 'lib/prefab/log_path_collector.rb', line 34

def push(path, severity)
  return unless @paths.size < @max_paths

  @paths.compute([path, severity], &INCREMENT)
end