Sha256: 692d19ccda54c7594dbace4e9929e2306871d9e1db51c999f28d47dc1941646c

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Coverband
  class AtExit
    @semaphore = Mutex.new

    @at_exit_registered = nil
    def self.register
      return if ENV['COVERBAND_DISABLE_AT_EXIT']
      return if @at_exit_registered

      @semaphore.synchronize do
        return if @at_exit_registered

        @at_exit_registered = true
        at_exit do
          ::Coverband::Background.stop

          #####
          # TODO: This is is brittle and not a great solution to avoid deploy time
          # actions polluting the 'runtime' metrics
          #
          # * should we skip /bin/rails webpacker:compile ?
          # * Perhaps detect heroku deployment ENV var opposed to tasks?
          #####
          default_heroku_tasks = ['assets:clean', 'assets:precompile']
          if defined?(Rake) && Rake.respond_to?(:application) && (Rake&.application&.top_level_tasks || []).any? { |task| default_heroku_tasks.include?(task) }
            # skip reporting
          else
            Coverband.report_coverage(true)
            #Coverband.configuration.logger&.debug('Coverband: Reported coverage before exit')
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coverband-4.2.0 lib/coverband/at_exit.rb
coverband-4.2.0.rc3 lib/coverband/at_exit.rb
coverband-4.2.0.rc2 lib/coverband/at_exit.rb