Class: GraphQL::Hive::UsageReporter
- Inherits:
-
Object
- Object
- GraphQL::Hive::UsageReporter
- 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
- #add_operation(operation) ⇒ Object
-
#initialize(options, client) ⇒ UsageReporter
constructor
A new instance of UsageReporter.
- #on_exit ⇒ Object
- #on_start ⇒ Object
Constructor Details
#initialize(options, client) ⇒ UsageReporter
Returns a new instance of UsageReporter.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/graphql-hive/usage_reporter.rb', line 17 def initialize(, client) @@instance = self @options = @client = client @options_mutex = Mutex.new @sampler = Sampler.new([:collect_usage_sampling], [:logger]) # NOTE: logs for deprecated field @queue = Thread::SizedQueue.new([:queue_size]) start_thread end |
Class Method Details
.instance ⇒ Object
13 14 15 |
# File 'lib/graphql-hive/usage_reporter.rb', line 13 def self.instance @@instance end |
Instance Method Details
#add_operation(operation) ⇒ Object
28 29 30 31 32 |
# File 'lib/graphql-hive/usage_reporter.rb', line 28 def add_operation(operation) @queue.push(operation, true) rescue ThreadError @options[:logger].error("SizedQueue is full, discarding operation. Size: #{@queue.size}, Max: #{@queue.max}") end |
#on_exit ⇒ Object
34 35 36 37 |
# File 'lib/graphql-hive/usage_reporter.rb', line 34 def on_exit @queue.close @thread.join end |
#on_start ⇒ Object
39 40 41 |
# File 'lib/graphql-hive/usage_reporter.rb', line 39 def on_start start_thread end |