Class: CI::Queue::FileLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ci/queue/file_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileLoader

Returns a new instance of FileLoader.



10
11
12
13
14
15
16
17
# File 'lib/ci/queue/file_loader.rb', line 10

def initialize
  @loaded_files = Set.new
  @failed_files = {}
  @pid = Process.pid
  @forked = false
  @load_stats = {}
  @loaded_features = nil
end

Instance Attribute Details

#load_statsObject (readonly)

Returns the value of attribute load_stats.



8
9
10
# File 'lib/ci/queue/file_loader.rb', line 8

def load_stats
  @load_stats
end

Instance Method Details

#load_file(file_path) ⇒ Object



19
20
21
22
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/ci/queue/file_loader.rb', line 19

def load_file(file_path)
  detect_fork!
  expanded = ::File.expand_path(file_path)
  return if @loaded_files.include?(expanded)

  if (cached_error = @failed_files[expanded])
    raise cached_error
  end

  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  error = nil

  begin
    required = with_warning_suppression { require expanded }
    if should_force_load_after_fork?(required, expanded)
      with_warning_suppression { load expanded }
    end
  rescue Exception => e
    raise if e.is_a?(SignalException) || e.is_a?(SystemExit)
    error = e
  ensure
    duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
    @load_stats[expanded] = duration
  end

  if error
    load_error = FileLoadError.new(file_path, error)
    @failed_files[expanded] = load_error
    raise load_error
  end

  remember_loaded_feature(expanded)
  @loaded_files.add(expanded)
  nil
end

#slowest_files(limit = 10) ⇒ Object



59
60
61
# File 'lib/ci/queue/file_loader.rb', line 59

def slowest_files(limit = 10)
  load_stats.sort_by { |_, duration| -duration }.take(limit)
end

#total_load_timeObject



55
56
57
# File 'lib/ci/queue/file_loader.rb', line 55

def total_load_time
  load_stats.values.sum
end