Sha256: 1d01584ee7d20bb741bd44ae6872f9514f418f1a66b33c43b99d5efabb682325
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
require 'dynoscale_ruby/api_wrapper' require 'dynoscale_ruby/recorder' require 'dynoscale_ruby/logger' module DynoscaleRuby class Reporter include Singleton extend Logger # Production delays REPORT_PUBLISH_FREQ = 30 # seconds REPORT_PUBLISH_RETRY_FREQ = 15 #seconds def self.start!(recorder, api_wrapper, break_after_first_iteration: false) @@reporter_thread ||= Thread.start do loop do if recorder.reports.any?(&:ready_to_publish?) api_wrapper.publish_reports(recorder.reports) do |success, published_reports, config| if success recorder.remove_published_reports!(published_reports) @@config = config Logger.logger.debug "Report publish was successful" sleep report_publish_freq else Logger.logger.error "Report publish failed" sleep report_publish_retry_freq end end else sleep report_publish_retry_freq end break if break_after_first_iteration end end end def self.running? @@reporter_thread ||= nil !!@@reporter_thread && @@reporter_thread.alive? end def self.report_publish_freq is_dev = ENV['DYNOSCALE_DEV'] == 'true' if is_dev 0 elsif @@config && @@config['publish_frequency'] @@config['publish_frequency']&.to_i || REPORT_PUBLISH_FREQ else REPORT_PUBLISH_FREQ end end def self.report_publish_retry_freq is_dev = ENV['DYNOSCALE_DEV'] == 'true' is_dev ? 0 : REPORT_PUBLISH_RETRY_FREQ end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dynoscale_ruby-1.0.3 | lib/dynoscale_ruby/reporter.rb |
dynoscale_ruby-1.0.2 | lib/dynoscale_ruby/reporter.rb |
dynoscale_ruby-1.0.1 | lib/dynoscale_ruby/reporter.rb |