Class: RailsPerformance::Gems::RakeExt

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_performance/gems/rake_ext.rb

Class Method Summary collapse

Class Method Details

.find_task_name(*args) ⇒ Object



36
37
38
# File 'lib/rails_performance/gems/rake_ext.rb', line 36

def self.find_task_name(*args)
  (ARGV + args).compact
end

.initObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_performance/gems/rake_ext.rb', line 4

def self.init
  ::Rake::Task.class_eval do
    def invoke_with_rails_performance(*args)
      now = Time.current
      status = "success"
      invoke_without_new_rails_performance(*args)
    rescue Exception => ex # rubocop:disable Lint/RescueException
      status = "error"
      raise(ex)
    ensure
      if !RailsPerformance.skipable_rake_tasks.include?(name)
        task_info = RailsPerformance::Gems::RakeExt.find_task_name(*args)
        task_info = [name] if task_info.empty?
        RailsPerformance::Models::RakeRecord.new(
          task: task_info,
          datetime: now.strftime(RailsPerformance::FORMAT),
          datetimei: now.to_i,
          duration: (Time.current - now) * 1000,
          status: status
        ).save
      end
    end

    alias_method :invoke_without_new_rails_performance, :invoke
    alias_method :invoke, :invoke_with_rails_performance

    def invoke(*args) # rubocop:disable Lint/DuplicateMethods
      invoke_with_rails_performance(*args)
    end
  end
end