Class: Knapsack::Presenter
- Inherits:
-
Object
- Object
- Knapsack::Presenter
- Defined in:
- lib/knapsack/presenter.rb
Class Method Summary collapse
- .exceeded_time ⇒ Object
- .global_time ⇒ Object
- .max_allowed_node_time_execution ⇒ Object
- .pretty_seconds(seconds) ⇒ Object
- .report_details ⇒ Object
- .report_json ⇒ Object
- .report_yml ⇒ Object
- .time_offset ⇒ Object
- .time_offset_log_level ⇒ Object
- .time_offset_warning ⇒ Object
Class Method Details
.exceeded_time ⇒ Object
33 34 35 36 |
# File 'lib/knapsack/presenter.rb', line 33 def exceeded_time exceeded_time = pretty_seconds(Knapsack.tracker.exceeded_time) "Exceeded time: #{exceeded_time}" end |
.global_time ⇒ Object
19 20 21 22 |
# File 'lib/knapsack/presenter.rb', line 19 def global_time global_time = pretty_seconds(Knapsack.tracker.global_time) "\nKnapsack global time execution for tests: #{global_time}" end |
.max_allowed_node_time_execution ⇒ Object
28 29 30 31 |
# File 'lib/knapsack/presenter.rb', line 28 def max_allowed_node_time_execution max_node_time_execution = pretty_seconds(Knapsack.tracker.max_node_time_execution) "Max allowed node time execution: #{max_node_time_execution}" end |
.pretty_seconds(seconds) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/knapsack/presenter.rb', line 79 def pretty_seconds(seconds) sign = '' if seconds < 0 seconds = seconds*-1 sign = '-' end return "#{sign}#{seconds}s" if seconds.abs < 1 time = Time.at(seconds).gmtime.strftime('%Hh %Mm %Ss') time_without_zeros = time.gsub(/00(h|m|s)/, '').strip sign + time_without_zeros end |
.report_details ⇒ Object
15 16 17 |
# File 'lib/knapsack/presenter.rb', line 15 def report_details "Knapsack report was generated. Preview:\n" + Presenter.report_json end |
.report_json ⇒ Object
11 12 13 |
# File 'lib/knapsack/presenter.rb', line 11 def report_json JSON.pretty_generate(Knapsack.tracker.test_files_with_time) end |
.report_yml ⇒ Object
7 8 9 |
# File 'lib/knapsack/presenter.rb', line 7 def report_yml Knapsack.tracker.test_files_with_time.to_yaml end |
.time_offset ⇒ Object
24 25 26 |
# File 'lib/knapsack/presenter.rb', line 24 def time_offset "Time offset: #{Knapsack.tracker.config[:time_offset_in_seconds]}s" end |
.time_offset_log_level ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/knapsack/presenter.rb', line 38 def time_offset_log_level if Knapsack.tracker.time_exceeded? Knapsack::Logger::WARN else Knapsack::Logger::INFO end end |
.time_offset_warning ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/knapsack/presenter.rb', line 46 def time_offset_warning str = %{\n========= Knapsack Time Offset Warning ========== #{Presenter.time_offset} #{Presenter.max_allowed_node_time_execution} #{Presenter.exceeded_time} } if Knapsack.tracker.time_exceeded? str << %{ Test on this CI node ran for longer than the max allowed node time execution. Please regenerate your knapsack report. If that doesn't help, you can split your slowest test files into smaller files, or bump up the time_offset_in_seconds setting. You can also allow the knapsack_pro gem to automatically divide your slow test files across parallel CI nodes. https://knapsackpro.com/faq/question/how-to-auto-split-test-files-by-test-cases-on-parallel-jobs-ci-nodes?utm_source=knapsack_gem&utm_medium=knapsack_gem_output&utm_campaign=knapsack_gem_time_offset_warning } else str << %{ Global time execution for this CI node is fine. Happy testing!} end str << "\n\nNeed explanation? See FAQ:" str << "\nhttps://docs.knapsackpro.com/ruby/knapsack#faq" str << "\n=================================================\n" str << %{Read up on the benefits of a dynamic test split with Knapsack Pro Queue Mode: https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation Sign up for Knapsack Pro here: https://knapsackpro.com} str << "\n=================================================\n" str end |