Class: CI::Queue::FileLoader
- Inherits:
-
Object
- Object
- CI::Queue::FileLoader
- Defined in:
- lib/ci/queue/file_loader.rb
Instance Attribute Summary collapse
-
#load_stats ⇒ Object
readonly
Returns the value of attribute load_stats.
Instance Method Summary collapse
-
#initialize ⇒ FileLoader
constructor
A new instance of FileLoader.
- #load_file(file_path) ⇒ Object
- #slowest_files(limit = 10) ⇒ Object
- #total_load_time ⇒ Object
Constructor Details
#initialize ⇒ FileLoader
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_stats ⇒ Object (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! = ::File.(file_path) return if @loaded_files.include?() if (cached_error = @failed_files[]) raise cached_error end start = Process.clock_gettime(Process::CLOCK_MONOTONIC) error = nil begin required = with_warning_suppression { require } if should_force_load_after_fork?(required, ) with_warning_suppression { load } 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[] = duration end if error load_error = FileLoadError.new(file_path, error) @failed_files[] = load_error raise load_error end remember_loaded_feature() @loaded_files.add() 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_time ⇒ Object
55 56 57 |
# File 'lib/ci/queue/file_loader.rb', line 55 def total_load_time load_stats.values.sum end |