Class: GraphQL::Hive::UsageReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql-hive/usage_reporter.rb

Overview

Report usage to Hive API without impacting application performances

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, client) ⇒ UsageReporter

Returns a new instance of UsageReporter.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/graphql-hive/usage_reporter.rb', line 17

def initialize(options, client)
  @@instance = self

  @options = options
  @client = client

  @options_mutex = Mutex.new
  @queue = Queue.new

  @sampler = Sampler.new(options[:collect_usage_sampling], options[:logger]) # NOTE: logs for deprecated field

  start_thread
end

Class Method Details

.instanceObject



13
14
15
# File 'lib/graphql-hive/usage_reporter.rb', line 13

def self.instance
  @@instance
end

Instance Method Details

#add_operation(operation) ⇒ Object



31
32
33
# File 'lib/graphql-hive/usage_reporter.rb', line 31

def add_operation(operation)
  @queue.push(operation)
end

#on_exitObject



35
36
37
38
# File 'lib/graphql-hive/usage_reporter.rb', line 35

def on_exit
  @queue.close
  @thread.join
end

#on_startObject



40
41
42
# File 'lib/graphql-hive/usage_reporter.rb', line 40

def on_start
  start_thread
end