Sha256: ce4d61e29c517dc8659105ad866541c2ad886d7c458d8283b85fe4ddb28de7d7

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Coverband
  class Background
    @semaphore = Mutex.new
    @thread = nil

    def self.stop
      return unless @thread

      @semaphore.synchronize do
        if @thread
          @thread.exit
          @thread = nil
        end
      end
    end

    def self.running?
      @thread&.alive?
    end

    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
        @thread = Thread.new do
          loop do
            Coverband.report_coverage
            Coverband.configuration.view_tracker&.report_views_tracked
            if Coverband.configuration.reporting_wiggle
              sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds + rand(Coverband.configuration.reporting_wiggle.to_i)
            end
            if Coverband.configuration.verbose
              logger.debug("Coverband: background reporting coverage (#{Coverband.configuration.store.type}). Sleeping #{sleep_seconds}s")
            end
            sleep(sleep_seconds)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
coverband-4.2.7 lib/coverband/integrations/background.rb
coverband-4.2.7.rc.1 lib/coverband/integrations/background.rb
coverband-4.2.6 lib/coverband/integrations/background.rb
coverband-4.2.5 lib/coverband/integrations/background.rb
coverband-4.2.5.rc.2 lib/coverband/integrations/background.rb
coverband-4.2.5.rc.1 lib/coverband/integrations/background.rb
coverband-4.2.4 lib/coverband/integrations/background.rb
coverband-4.2.4.rc.3 lib/coverband/integrations/background.rb