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



39
40
41
# File 'lib/rails_performance/gems/rake_ext.rb', line 39

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

.initObject



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
35
36
37
# File 'lib/rails_performance/gems/rake_ext.rb', line 5

def self.init
  ::Rake::Task.class_eval do
    def invoke_with_rails_performance(*args)
      begin
        now    = Time.current
        status = 'success'
        invoke_without_new_rails_performance(*args)
      rescue Exception => ex
        status = 'error'
        raise(ex)
      ensure
        if !RailsPerformance.skipable_rake_tasks.include?(self.name)
          task_info = RailsPerformance::Gems::RakeExt.find_task_name(*args)
          task_info = [self.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
    end

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

    def invoke(*args)
      invoke_with_rails_performance(*args)
    end
  end
end