Class: Coverband::Background
- Inherits:
-
Object
- Object
- Coverband::Background
- Defined in:
- lib/coverband/integrations/background.rb
Class Method Summary collapse
Class Method Details
.running? ⇒ Boolean
19 20 21 |
# File 'lib/coverband/integrations/background.rb', line 19 def self.running? @thread&.alive? end |
.start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coverband/integrations/background.rb', line 23 def self.start return if running? logger = Coverband.configuration.logger @semaphore.synchronize do return if running? logger.debug("Coverband: Starting background reporting") if Coverband.configuration.verbose sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i @thread = Thread.new { Thread.current.name = "Coverband Background Reporter" loop do if Coverband.configuration.reporting_wiggle sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i + rand(Coverband.configuration.reporting_wiggle.to_i) end # NOTE: Normally as processes first start we immediately report, this causes a redis spike on deploys # if deferred is set also sleep frst to spread load sleep(sleep_seconds.to_i) if Coverband.configuration.defer_eager_loading_data? Coverband.report_coverage Coverband.configuration.trackers.each { |tracker| tracker.save_report } if Coverband.configuration.verbose logger.debug("Coverband: background reporting coverage (#{Coverband.configuration.store.type}). Sleeping #{sleep_seconds}s") end sleep(sleep_seconds.to_i) unless Coverband.configuration.defer_eager_loading_data? end } end rescue ThreadError stop end |
.stop ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/coverband/integrations/background.rb', line 8 def self.stop return unless @thread @semaphore.synchronize do if @thread @thread.exit @thread = nil end end end |